weboptimizer 3.0.28 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.js +93 -205
- package/configurator.js +222 -335
- package/ejsLoader.js +212 -170
- package/eslint.config.mjs +4 -0
- package/helper.js +230 -540
- package/index.js +245 -574
- package/jestSetup.js +7 -5
- package/package.json +31 -35
- package/plugins/HTMLTransformation.js +68 -109
- package/plugins/InPlaceAssetsIntoHTML.js +66 -69
- package/stylelintConfigurator.js +4 -8
- package/type.js +15 -6
- package/webpackConfigurator.js +389 -600
package/webpackConfigurator.js
CHANGED
|
@@ -16,60 +16,55 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
import "core-js/modules/es.array.push.js";
|
|
20
|
+
import "core-js/modules/es.array.unshift.js";
|
|
21
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
22
|
+
import "core-js/modules/es.iterator.filter.js";
|
|
23
|
+
import "core-js/modules/es.iterator.map.js";
|
|
24
|
+
import { convertToValidVariableName, evaluate, EvaluationResult, escapeRegularExpressions, extend, isFileSync, isObject, isPlainObject, Logger, Mapping, mask, PlainObject, PositiveEvaluationResult, RecursivePartial, represent, Unpacked } from 'clientnode';
|
|
25
|
+
import { PluginOptions as ImageMinimizerOptions } from 'image-minimizer-webpack-plugin';
|
|
26
|
+
import { extname, join, relative, resolve } from 'path';
|
|
27
|
+
import { Transformer as PostcssTransformer } from 'postcss';
|
|
28
|
+
import PostcssNode from 'postcss/lib/node';
|
|
29
|
+
import util from 'util';
|
|
30
|
+
import { Chunk, Compiler, Compilation, ContextReplacementPlugin, DefinePlugin, HotModuleReplacementPlugin, IgnorePlugin, NormalModuleReplacementPlugin, ProvidePlugin, RuleSetRule } from 'webpack';
|
|
31
|
+
import { RawSource as WebpackRawSource } from 'webpack-sources';
|
|
32
|
+
import { InjectManifestOptions as WorkboxInjectManifestOptions } from 'workbox-build';
|
|
33
|
+
import getConfiguration from './configurator';
|
|
34
|
+
import { LoaderConfiguration as EJSLoaderConfiguration } from './ejsLoader';
|
|
35
|
+
import { determineAssetType, determineExternalRequest, determineModuleFilePath, getClosestPackageDescriptor, isFilePathInLocation, normalizePaths, stripLoader } from './helper';
|
|
36
|
+
import InPlaceAssetsIntoHTML from './plugins/InPlaceAssetsIntoHTML';
|
|
37
|
+
import HTMLTransformation from './plugins/HTMLTransformation';
|
|
38
|
+
import { AdditionalLoaderConfiguration, AssetPathConfiguration, EvaluationScope, GenericLoader, HTMLConfiguration, IgnorePattern, InPlaceConfiguration, Loader, PackageDescriptor, RedundantRequest, ResolvedConfiguration, RuleSet, WebpackConfiguration, WebpackExtendedResolveData, WebpackLoader, WebpackLoaderConfiguration, WebpackLoaderIndicator, WebpackPlugin, WebpackPlugins, WebpackResolveData } from './type';
|
|
39
|
+
export const log = new Logger({
|
|
40
|
+
name: 'weboptimizer.webpack-configurator'
|
|
22
41
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
26
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
27
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
28
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
29
|
-
var _clientnode = require("clientnode");
|
|
30
|
-
var _path = require("path");
|
|
31
|
-
var _util = _interopRequireDefault(require("util"));
|
|
32
|
-
var _webpack = require("webpack");
|
|
33
|
-
var _webpackSources = require("webpack-sources");
|
|
34
|
-
var _configurator = _interopRequireDefault(require("./configurator"));
|
|
35
|
-
var _helper = require("./helper");
|
|
36
|
-
var _InPlaceAssetsIntoHTML = _interopRequireDefault(require("./plugins/InPlaceAssetsIntoHTML"));
|
|
37
|
-
var _HTMLTransformation = _interopRequireDefault(require("./plugins/HTMLTransformation"));
|
|
38
|
-
var _process$env$NODE_ENV, _optionalRequire, _configuration$cache$, _configuration$cache, _configuration$cache2, _configuration$cache3;
|
|
39
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
40
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
41
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
42
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
43
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
44
|
-
var log = exports.log = new _clientnode.Logger({
|
|
45
|
-
name: 'weboptimizer-webpack-configurator-logger'
|
|
46
|
-
});
|
|
47
|
-
_clientnode.Logger.configureAllInstances({
|
|
48
|
-
level: ['debug', 'development'].includes((_process$env$NODE_ENV = process.env.NODE_ENV) !== null && _process$env$NODE_ENV !== void 0 ? _process$env$NODE_ENV : '') ? 'debug' : 'warn'
|
|
42
|
+
Logger.configureAllInstances({
|
|
43
|
+
level: ['debug', 'development'].includes(process.env.NODE_ENV ?? '') ? 'debug' : 'warn'
|
|
49
44
|
});
|
|
50
45
|
/// region optional imports
|
|
51
46
|
// NOTE: Has to be defined here to ensure to resolve from here.
|
|
52
|
-
|
|
47
|
+
const currentRequire =
|
|
53
48
|
/*
|
|
54
49
|
typeof __non_webpack_require__ === 'function' ?
|
|
55
50
|
__non_webpack_require__ :
|
|
56
51
|
*/
|
|
57
|
-
eval(
|
|
58
|
-
|
|
52
|
+
eval(`typeof require === 'undefined' ? null : require`);
|
|
53
|
+
export const optionalRequire = id => {
|
|
59
54
|
try {
|
|
60
55
|
return currentRequire ? currentRequire(id) : null;
|
|
61
|
-
} catch
|
|
56
|
+
} catch {
|
|
62
57
|
return null;
|
|
63
58
|
}
|
|
64
59
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
const postcssCSSnano = optionalRequire('cssnano');
|
|
61
|
+
const postcssFontpath = optionalRequire('postcss-fontpath');
|
|
62
|
+
const postcssImport = optionalRequire('postcss-import');
|
|
63
|
+
const postcssSprites = optionalRequire('postcss-sprites');
|
|
64
|
+
const updateRule = optionalRequire('postcss-sprites/lib/core')?.updateRule;
|
|
65
|
+
const postcssURL = optionalRequire('postcss-url');
|
|
71
66
|
/// endregion
|
|
72
|
-
|
|
67
|
+
const pluginNameResourceMapping = {
|
|
73
68
|
Favicon: 'favicons-webpack-plugin',
|
|
74
69
|
ImageMinimizer: 'image-minimizer-webpack-plugin',
|
|
75
70
|
HTML: 'html-webpack-plugin',
|
|
@@ -77,137 +72,96 @@ var pluginNameResourceMapping = {
|
|
|
77
72
|
offline: 'workbox-webpack-plugin',
|
|
78
73
|
Terser: 'terser-webpack-plugin'
|
|
79
74
|
};
|
|
80
|
-
|
|
81
|
-
for (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
alias = _Object$entries$_i[1];
|
|
85
|
-
var plugin = optionalRequire(alias);
|
|
86
|
-
if (plugin) plugins[name] = plugin;else log.debug("Optional webpack plugin \"".concat(name, "\" not available."));
|
|
75
|
+
const plugins = {};
|
|
76
|
+
for (const [name, alias] of Object.entries(pluginNameResourceMapping)) {
|
|
77
|
+
const plugin = optionalRequire(alias);
|
|
78
|
+
if (plugin) plugins[name] = plugin;else log.debug(`Optional webpack plugin "${name}" not available.`);
|
|
87
79
|
}
|
|
88
80
|
// endregion
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
const configuration = getConfiguration();
|
|
82
|
+
Logger.configureAllInstances({
|
|
91
83
|
level: configuration.debug ? 'debug' : 'warn'
|
|
92
84
|
});
|
|
93
|
-
|
|
85
|
+
const module = configuration.module;
|
|
94
86
|
// region initialization
|
|
95
87
|
/// region determine library name
|
|
96
|
-
|
|
88
|
+
let libraryName;
|
|
97
89
|
if (configuration.libraryName) libraryName = configuration.libraryName;else if (Object.keys(configuration.injection.entry.normalized).length > 1) libraryName = '[name]';else {
|
|
98
90
|
libraryName = configuration.name;
|
|
99
|
-
if (['assign', 'global', 'this', 'var', 'window'].includes(configuration.exportFormat.self)) libraryName =
|
|
91
|
+
if (['assign', 'global', 'this', 'var', 'window'].includes(configuration.exportFormat.self)) libraryName = convertToValidVariableName(libraryName);
|
|
100
92
|
}
|
|
101
|
-
if (libraryName === '*') libraryName = ['assign', 'global', 'this', 'var', 'window'].includes(configuration.exportFormat.self) ? Object.keys(configuration.injection.entry.normalized).map(
|
|
102
|
-
return (0, _clientnode.convertToValidVariableName)(name);
|
|
103
|
-
}) : undefined;
|
|
93
|
+
if (libraryName === '*') libraryName = ['assign', 'global', 'this', 'var', 'window'].includes(configuration.exportFormat.self) ? Object.keys(configuration.injection.entry.normalized).map(name => convertToValidVariableName(name)) : undefined;
|
|
104
94
|
/// endregion
|
|
105
95
|
/// region plugins
|
|
106
|
-
|
|
96
|
+
const pluginInstances = [];
|
|
107
97
|
//// region define modules to ignore
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var pattern = _step.value;
|
|
113
|
-
if (typeof pattern.contextRegExp === 'string') pattern.contextRegExp = new RegExp(pattern.contextRegExp);
|
|
114
|
-
if (typeof pattern.resourceRegExp === 'string') pattern.resourceRegExp = new RegExp(pattern.resourceRegExp);
|
|
115
|
-
pluginInstances.push(new _webpack.IgnorePlugin(pattern));
|
|
116
|
-
}
|
|
117
|
-
//// endregion
|
|
118
|
-
//// region define modules to replace
|
|
119
|
-
} catch (err) {
|
|
120
|
-
_iterator.e(err);
|
|
121
|
-
} finally {
|
|
122
|
-
_iterator.f();
|
|
98
|
+
for (const pattern of [].concat(configuration.injection.ignorePattern)) {
|
|
99
|
+
if (typeof pattern.contextRegExp === 'string') pattern.contextRegExp = new RegExp(pattern.contextRegExp);
|
|
100
|
+
if (typeof pattern.resourceRegExp === 'string') pattern.resourceRegExp = new RegExp(pattern.resourceRegExp);
|
|
101
|
+
pluginInstances.push(new IgnorePlugin(pattern));
|
|
123
102
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
pluginInstances.push(new _webpack.NormalModuleReplacementPlugin(search, function (resource) {
|
|
103
|
+
//// endregion
|
|
104
|
+
//// region define modules to replace
|
|
105
|
+
for (const [source, replacement] of Object.entries(module.replacements.normal)) {
|
|
106
|
+
const search = new RegExp(source);
|
|
107
|
+
pluginInstances.push(new NormalModuleReplacementPlugin(search, resource => {
|
|
130
108
|
resource.request = resource.request.replace(search, replacement);
|
|
131
109
|
}));
|
|
132
|
-
};
|
|
133
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries(_module.replacements.normal); _i2 < _Object$entries2.length; _i2++) {
|
|
134
|
-
_loop();
|
|
135
110
|
}
|
|
136
111
|
//// endregion
|
|
137
112
|
//// region generate html file
|
|
138
|
-
|
|
139
|
-
if (plugins.HTML) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if ((0, _clientnode.isFileSync)(htmlConfiguration.template.filePath)) {
|
|
146
|
-
pluginInstances.push(new plugins.HTML(_objectSpread(_objectSpread({}, htmlConfiguration), {}, {
|
|
147
|
-
template: htmlConfiguration.template.request
|
|
148
|
-
})));
|
|
149
|
-
htmlAvailable = true;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
} catch (err) {
|
|
153
|
-
_iterator2.e(err);
|
|
154
|
-
} finally {
|
|
155
|
-
_iterator2.f();
|
|
156
|
-
}
|
|
113
|
+
let htmlAvailable = false;
|
|
114
|
+
if (plugins.HTML) for (const htmlConfiguration of configuration.files.html) if (isFileSync(htmlConfiguration.template.filePath)) {
|
|
115
|
+
pluginInstances.push(new plugins.HTML({
|
|
116
|
+
...htmlConfiguration,
|
|
117
|
+
template: htmlConfiguration.template.request
|
|
118
|
+
}));
|
|
119
|
+
htmlAvailable = true;
|
|
157
120
|
}
|
|
158
121
|
//// endregion
|
|
159
122
|
//// region generate favicons
|
|
160
|
-
if (htmlAvailable && Object.prototype.hasOwnProperty.call(configuration, 'favicon') && plugins.Favicon &&
|
|
123
|
+
if (htmlAvailable && Object.prototype.hasOwnProperty.call(configuration, 'favicon') && plugins.Favicon && isFileSync([].concat(configuration.favicon.logo)[0])) pluginInstances.push(new plugins.Favicon(configuration.favicon));
|
|
161
124
|
//// endregion
|
|
162
125
|
//// region provide offline functionality
|
|
163
126
|
if (htmlAvailable && configuration.offline && Object.prototype.hasOwnProperty.call(plugins, 'offline')) {
|
|
164
|
-
if (!['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2])) for (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
_name = _Object$entries3$_i[0],
|
|
170
|
-
extension = _Object$entries3$_i[1];
|
|
171
|
-
var type = _name;
|
|
127
|
+
if (!['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2])) for (const [name, extension] of Object.entries({
|
|
128
|
+
cascadingStyleSheet: 'css',
|
|
129
|
+
javaScript: 'js'
|
|
130
|
+
})) {
|
|
131
|
+
const type = name;
|
|
172
132
|
if (configuration.inPlace[type]) {
|
|
173
|
-
|
|
133
|
+
const matches = Object.keys(configuration.inPlace[type]);
|
|
174
134
|
if (!Array.isArray(configuration.offline.common.excludeChunks)) configuration.offline.common.excludeChunks = [];
|
|
175
|
-
for (
|
|
176
|
-
var _name2 = _matches[_i4];
|
|
177
|
-
configuration.offline.common.excludeChunks.push((0, _path.relative)(configuration.path.target.base, configuration.path.target.asset[type]) + "".concat(_name2, ".").concat(extension, "?").concat(configuration.hashAlgorithm, "=*"));
|
|
178
|
-
}
|
|
135
|
+
for (const name of matches) configuration.offline.common.excludeChunks.push(relative(configuration.path.target.base, configuration.path.target.asset[type]) + `${name}.${extension}?${configuration.hashAlgorithm}=*`);
|
|
179
136
|
}
|
|
180
137
|
}
|
|
181
138
|
if (plugins.offline) {
|
|
182
|
-
if ([].concat(configuration.offline.use).includes('injectionManifest')) pluginInstances.push(new plugins.offline.InjectManifest(
|
|
183
|
-
if ([].concat(configuration.offline.use).includes('generateServiceWorker')) pluginInstances.push(new plugins.offline.GenerateSW(
|
|
139
|
+
if ([].concat(configuration.offline.use).includes('injectionManifest')) pluginInstances.push(new plugins.offline.InjectManifest(extend(true, configuration.offline.common, configuration.offline.injectionManifest)));
|
|
140
|
+
if ([].concat(configuration.offline.use).includes('generateServiceWorker')) pluginInstances.push(new plugins.offline.GenerateSW(extend(true, configuration.offline.common, configuration.offline.generateServiceWorker)));
|
|
184
141
|
}
|
|
185
142
|
}
|
|
186
143
|
//// endregion
|
|
187
144
|
//// region provide build environment
|
|
188
|
-
if (Object.prototype.hasOwnProperty.call(configuration.buildContext, 'definitions')) pluginInstances.push(new
|
|
189
|
-
if (
|
|
145
|
+
if (Object.prototype.hasOwnProperty.call(configuration.buildContext, 'definitions')) pluginInstances.push(new DefinePlugin(configuration.buildContext.definitions));
|
|
146
|
+
if (module.provide) pluginInstances.push(new ProvidePlugin(module.provide));
|
|
190
147
|
//// endregion
|
|
191
148
|
//// region modules/assets
|
|
192
149
|
///// region apply module pattern
|
|
193
150
|
pluginInstances.push({
|
|
194
|
-
apply:
|
|
195
|
-
|
|
196
|
-
compiler.hooks.compilation.tap(name,
|
|
151
|
+
apply: compiler => {
|
|
152
|
+
const name = 'ApplyModulePattern';
|
|
153
|
+
compiler.hooks.compilation.tap(name, compilation => {
|
|
197
154
|
compilation.hooks.processAssets.tap({
|
|
198
|
-
name
|
|
155
|
+
name,
|
|
199
156
|
additionalAssets: true,
|
|
200
|
-
stage:
|
|
201
|
-
},
|
|
202
|
-
for (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (_type && Object.prototype.hasOwnProperty.call(configuration.assetPattern, _type) && new RegExp(configuration.assetPattern[_type].includeFilePathRegularExpression).test(filePath) && !new RegExp(configuration.assetPattern[_type].excludeFilePathRegularExpression).test(filePath)) {
|
|
209
|
-
var source = asset.source();
|
|
210
|
-
if (typeof source === 'string') compilation.assets[request] = new _webpackSources.RawSource(configuration.assetPattern[_type].pattern.replace(/\{1\}/g, source.replace(/\$/g, '$$$')));
|
|
157
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
158
|
+
}, assets => {
|
|
159
|
+
for (const [request, asset] of Object.entries(assets)) {
|
|
160
|
+
const filePath = request.replace(/\?[^?]+$/, '');
|
|
161
|
+
const type = determineAssetType(filePath, configuration.buildContext.types, configuration.path);
|
|
162
|
+
if (type && Object.prototype.hasOwnProperty.call(configuration.assetPattern, type) && new RegExp(configuration.assetPattern[type].includeFilePathRegularExpression).test(filePath) && !new RegExp(configuration.assetPattern[type].excludeFilePathRegularExpression).test(filePath)) {
|
|
163
|
+
const source = asset.source();
|
|
164
|
+
if (typeof source === 'string') compilation.assets[request] = new WebpackRawSource(configuration.assetPattern[type].pattern.replace(/\{1\}/g, source.replace(/\$/g, '$$$')));
|
|
211
165
|
}
|
|
212
166
|
}
|
|
213
167
|
});
|
|
@@ -216,19 +170,19 @@ pluginInstances.push({
|
|
|
216
170
|
});
|
|
217
171
|
///// endregion
|
|
218
172
|
///// region in-place configured assets in the main html file
|
|
219
|
-
if (plugins.HTML && htmlAvailable && !['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2]) && configuration.inPlace.cascadingStyleSheet && Object.keys(configuration.inPlace.cascadingStyleSheet).length || configuration.inPlace.javaScript && Object.keys(configuration.inPlace.javaScript).length) pluginInstances.push(new
|
|
173
|
+
if (plugins.HTML && htmlAvailable && !['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2]) && configuration.inPlace.cascadingStyleSheet && Object.keys(configuration.inPlace.cascadingStyleSheet).length || configuration.inPlace.javaScript && Object.keys(configuration.inPlace.javaScript).length) pluginInstances.push(new InPlaceAssetsIntoHTML({
|
|
220
174
|
cascadingStyleSheet: configuration.inPlace.cascadingStyleSheet,
|
|
221
175
|
javaScript: configuration.inPlace.javaScript,
|
|
222
176
|
htmlPlugin: plugins.HTML
|
|
223
177
|
}));
|
|
224
178
|
///// endregion
|
|
225
179
|
///// region mark empty javaScript modules as dummy
|
|
226
|
-
if (!(configuration.needed.javaScript || configuration.needed.javaScriptExtension || configuration.needed.typeScript || configuration.needed.typeScriptExtension)) configuration.files.compose.javaScript =
|
|
180
|
+
if (!(configuration.needed.javaScript || configuration.needed.javaScriptExtension || configuration.needed.typeScript || configuration.needed.typeScriptExtension)) configuration.files.compose.javaScript = resolve(configuration.path.target.asset.javaScript, '.__dummy__.compiled.js');
|
|
227
181
|
///// endregion
|
|
228
182
|
///// region extract cascading style sheets
|
|
229
|
-
|
|
183
|
+
const cssOutputPath = configuration.files.compose.cascadingStyleSheet;
|
|
230
184
|
if (cssOutputPath && plugins.MiniCSSExtract) pluginInstances.push(new plugins.MiniCSSExtract({
|
|
231
|
-
filename: typeof cssOutputPath === 'string' ?
|
|
185
|
+
filename: typeof cssOutputPath === 'string' ? relative(configuration.path.target.base, cssOutputPath) : cssOutputPath
|
|
232
186
|
}));
|
|
233
187
|
///// endregion
|
|
234
188
|
///// region performs implicit external logic
|
|
@@ -240,118 +194,62 @@ if (configuration.injection.external.modules === '__implicit__')
|
|
|
240
194
|
NOTE: Only native javascript and json modules will be marked as
|
|
241
195
|
external dependency.
|
|
242
196
|
*/
|
|
243
|
-
configuration.injection.external.modules =
|
|
244
|
-
|
|
245
|
-
|
|
197
|
+
configuration.injection.external.modules = ({
|
|
198
|
+
context,
|
|
199
|
+
request
|
|
200
|
+
}, callback) => {
|
|
246
201
|
if (typeof request !== 'string') {
|
|
247
202
|
callback();
|
|
248
203
|
return;
|
|
249
204
|
}
|
|
250
205
|
request = request.replace(/^!+/, '');
|
|
251
|
-
if (request.startsWith('/')) request =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
var _filePath = _step3.value;
|
|
257
|
-
if (request.startsWith(_filePath)) {
|
|
258
|
-
request = request.substring(_filePath.length);
|
|
259
|
-
if (request.startsWith('/')) request = request.substring(1);
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// region pattern based aliasing
|
|
264
|
-
} catch (err) {
|
|
265
|
-
_iterator3.e(err);
|
|
266
|
-
} finally {
|
|
267
|
-
_iterator3.f();
|
|
206
|
+
if (request.startsWith('/')) request = relative(configuration.path.context, request);
|
|
207
|
+
for (const filePath of module.directoryNames) if (request.startsWith(filePath)) {
|
|
208
|
+
request = request.substring(filePath.length);
|
|
209
|
+
if (request.startsWith('/')) request = request.substring(1);
|
|
210
|
+
break;
|
|
268
211
|
}
|
|
269
|
-
|
|
212
|
+
// region pattern based aliasing
|
|
213
|
+
const filePath = determineModuleFilePath(request, {}, {}, {
|
|
270
214
|
file: configuration.extensions.file.external
|
|
271
|
-
}, configuration.path.context, context, configuration.path.ignore,
|
|
272
|
-
if (filePath) for (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
} else match = true;
|
|
291
|
-
if (match) {
|
|
292
|
-
request = request.replace(replacementRegularExpression, target);
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
215
|
+
}, configuration.path.context, context, configuration.path.ignore, module.directoryNames, configuration.package.main.fileNames, configuration.package.main.propertyNames, configuration.package.aliasPropertyNames, configuration.encoding);
|
|
216
|
+
if (filePath) for (const [pattern, targetConfiguration] of Object.entries(configuration.injection.external.aliases)) if (targetConfiguration && pattern.startsWith('^')) {
|
|
217
|
+
const regularExpression = new RegExp(pattern);
|
|
218
|
+
if (regularExpression.test(filePath)) {
|
|
219
|
+
let match = false;
|
|
220
|
+
const firstKey = Object.keys(targetConfiguration)[0];
|
|
221
|
+
let target = targetConfiguration[firstKey];
|
|
222
|
+
if (typeof target !== 'string') break;
|
|
223
|
+
const replacementRegularExpression = new RegExp(firstKey);
|
|
224
|
+
if (target.startsWith('?')) {
|
|
225
|
+
target = target.substring(1);
|
|
226
|
+
const aliasedRequest = request.replace(replacementRegularExpression, target);
|
|
227
|
+
if (aliasedRequest !== request) match = Boolean(determineModuleFilePath(aliasedRequest, {}, {}, {
|
|
228
|
+
file: configuration.extensions.file.external
|
|
229
|
+
}, configuration.path.context, context, configuration.path.ignore, module.directoryNames, configuration.package.main.fileNames, configuration.package.main.propertyNames, configuration.package.aliasPropertyNames, configuration.encoding));
|
|
230
|
+
} else match = true;
|
|
231
|
+
if (match) {
|
|
232
|
+
request = request.replace(replacementRegularExpression, target);
|
|
233
|
+
break;
|
|
295
234
|
}
|
|
296
235
|
}
|
|
297
236
|
}
|
|
298
237
|
// endregion
|
|
299
|
-
|
|
238
|
+
const resolvedRequest = determineExternalRequest(request, configuration.path.context, context, configuration.injection.entry.normalized, module.directoryNames, module.aliases, module.replacements.normal, configuration.extensions, configuration.path.source.asset.base, configuration.path.ignore, module.directoryNames, configuration.package.main.fileNames, configuration.package.main.propertyNames, configuration.package.aliasPropertyNames, configuration.injection.external.implicit.pattern.include, configuration.injection.external.implicit.pattern.exclude, configuration.inPlace.externalLibrary.normal, configuration.inPlace.externalLibrary.dynamic, configuration.encoding);
|
|
300
239
|
if (resolvedRequest) {
|
|
301
|
-
|
|
302
|
-
|
|
240
|
+
const keys = ['amd', 'commonjs', 'commonjs2', 'root'];
|
|
241
|
+
let result = resolvedRequest;
|
|
303
242
|
if (Object.prototype.hasOwnProperty.call(configuration.injection.external.aliases, request)) {
|
|
304
243
|
// region normal alias replacement
|
|
305
244
|
result = {
|
|
306
|
-
|
|
245
|
+
default: request
|
|
307
246
|
};
|
|
308
|
-
if (typeof configuration.injection.external.aliases[request] === 'string')
|
|
309
|
-
|
|
310
|
-
_step4;
|
|
311
|
-
try {
|
|
312
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
313
|
-
var key = _step4.value;
|
|
314
|
-
result[key] = configuration.injection.external.aliases[request];
|
|
315
|
-
}
|
|
316
|
-
} catch (err) {
|
|
317
|
-
_iterator4.e(err);
|
|
318
|
-
} finally {
|
|
319
|
-
_iterator4.f();
|
|
320
|
-
}
|
|
321
|
-
} else if (typeof configuration.injection.external.aliases[request] === 'function') {
|
|
322
|
-
var _iterator5 = _createForOfIteratorHelper(keys),
|
|
323
|
-
_step5;
|
|
324
|
-
try {
|
|
325
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
326
|
-
var _key2 = _step5.value;
|
|
327
|
-
result[_key2] = configuration.injection.external.aliases[request](request, _key2);
|
|
328
|
-
}
|
|
329
|
-
} catch (err) {
|
|
330
|
-
_iterator5.e(err);
|
|
331
|
-
} finally {
|
|
332
|
-
_iterator5.f();
|
|
333
|
-
}
|
|
334
|
-
} else if ((0, _clientnode.isObject)(configuration.injection.external.aliases[request])) (0, _clientnode.extend)(result, configuration.injection.external.aliases[request]);
|
|
335
|
-
if (Object.prototype.hasOwnProperty.call(result, 'default')) {
|
|
336
|
-
var _iterator6 = _createForOfIteratorHelper(keys),
|
|
337
|
-
_step6;
|
|
338
|
-
try {
|
|
339
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
340
|
-
var _key3 = _step6.value;
|
|
341
|
-
if (!Object.prototype.hasOwnProperty.call(result, _key3)) result[_key3] = result["default"];
|
|
342
|
-
}
|
|
343
|
-
} catch (err) {
|
|
344
|
-
_iterator6.e(err);
|
|
345
|
-
} finally {
|
|
346
|
-
_iterator6.f();
|
|
347
|
-
}
|
|
348
|
-
}
|
|
247
|
+
if (typeof configuration.injection.external.aliases[request] === 'string') for (const key of keys) result[key] = configuration.injection.external.aliases[request];else if (typeof configuration.injection.external.aliases[request] === 'function') for (const key of keys) result[key] = configuration.injection.external.aliases[request](request, key);else if (isObject(configuration.injection.external.aliases[request])) extend(result, configuration.injection.external.aliases[request]);
|
|
248
|
+
if (Object.prototype.hasOwnProperty.call(result, 'default')) for (const key of keys) if (!Object.prototype.hasOwnProperty.call(result, key)) result[key] = result.default;
|
|
349
249
|
// endregion
|
|
350
250
|
}
|
|
351
|
-
if (typeof result !== 'string' && Object.prototype.hasOwnProperty.call(result, 'root') && Array.isArray(result.root)) result.root = [].concat(result.root).map(
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
var exportFormat = Object.prototype.hasOwnProperty.call(configuration.exportFormat, 'external') ? configuration.exportFormat.external : configuration.exportFormat.self;
|
|
251
|
+
if (typeof result !== 'string' && Object.prototype.hasOwnProperty.call(result, 'root') && Array.isArray(result.root)) result.root = [].concat(result.root).map(name => convertToValidVariableName(name));
|
|
252
|
+
const exportFormat = Object.prototype.hasOwnProperty.call(configuration.exportFormat, 'external') ? configuration.exportFormat.external : configuration.exportFormat.self;
|
|
355
253
|
callback(undefined, exportFormat === 'umd' || typeof result === 'string' ? result : result[exportFormat], exportFormat);
|
|
356
254
|
return;
|
|
357
255
|
}
|
|
@@ -360,122 +258,93 @@ if (configuration.injection.external.modules === '__implicit__')
|
|
|
360
258
|
///// endregion
|
|
361
259
|
//// endregion
|
|
362
260
|
//// region apply final html modifications/fixes
|
|
363
|
-
if (htmlAvailable && plugins.HTML) pluginInstances.push(new
|
|
261
|
+
if (htmlAvailable && plugins.HTML) pluginInstances.push(new HTMLTransformation({
|
|
364
262
|
hashAlgorithm: configuration.hashAlgorithm,
|
|
365
263
|
htmlPlugin: plugins.HTML,
|
|
366
264
|
files: configuration.files.html
|
|
367
265
|
}));
|
|
368
266
|
//// endregion
|
|
369
267
|
//// region context replacements
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
} catch (err) {
|
|
394
|
-
_iterator7.e(err);
|
|
395
|
-
} finally {
|
|
396
|
-
_iterator7.f();
|
|
397
|
-
}
|
|
398
|
-
if (_module.enforceDeduplication) {
|
|
399
|
-
var absoluteContextPath = (0, _path.resolve)(configuration.path.context);
|
|
400
|
-
var consolidator = function consolidator(result) {
|
|
401
|
-
var targetPath = result.createData.resource;
|
|
402
|
-
if (targetPath && /((?: ^|\/)node_modules\/.+)/.test(targetPath) && (!targetPath.startsWith(absoluteContextPath) || /((?: ^|\/)node_modules\/.+){2}/.test(targetPath)) && (0, _clientnode.isFileSync)(targetPath)) {
|
|
403
|
-
var packageDescriptor = (0, _helper.getClosestPackageDescriptor)(targetPath);
|
|
268
|
+
for (const contextReplacement of module.replacements.context) pluginInstances.push(new ContextReplacementPlugin(...contextReplacement.map(value => {
|
|
269
|
+
const evaluated = evaluate(value, {
|
|
270
|
+
configuration,
|
|
271
|
+
__dirname,
|
|
272
|
+
__filename
|
|
273
|
+
});
|
|
274
|
+
if (evaluated.error) throw new Error('Error occurred during processing given context ' + `replacement: ${evaluated.error}`);
|
|
275
|
+
return evaluated.result;
|
|
276
|
+
})));
|
|
277
|
+
//// endregion
|
|
278
|
+
//// region consolidate duplicated module requests
|
|
279
|
+
/*
|
|
280
|
+
NOTE: Redundancies usually occur when symlinks aren't converted to their
|
|
281
|
+
real paths since real paths can be de-duplicated by webpack but if two
|
|
282
|
+
linked modules share the same transitive dependency webpack wont recognize
|
|
283
|
+
them as same dependency.
|
|
284
|
+
*/
|
|
285
|
+
if (module.enforceDeduplication) {
|
|
286
|
+
const absoluteContextPath = resolve(configuration.path.context);
|
|
287
|
+
const consolidator = result => {
|
|
288
|
+
const targetPath = result.createData.resource;
|
|
289
|
+
if (targetPath && /((?: ^|\/)node_modules\/.+)/.test(targetPath) && (!targetPath.startsWith(absoluteContextPath) || /((?: ^|\/)node_modules\/.+){2}/.test(targetPath)) && isFileSync(targetPath)) {
|
|
290
|
+
const packageDescriptor = getClosestPackageDescriptor(targetPath);
|
|
404
291
|
if (packageDescriptor) {
|
|
405
|
-
|
|
406
|
-
|
|
292
|
+
let pathPrefixes;
|
|
293
|
+
let pathSuffix;
|
|
407
294
|
if (targetPath.startsWith(absoluteContextPath)) {
|
|
408
|
-
|
|
409
|
-
if (
|
|
410
|
-
pathPrefixes = Array.from(
|
|
295
|
+
const matches = targetPath.match(/((?: ^|.*?\/)node_modules\/)/g);
|
|
296
|
+
if (matches === null) return;
|
|
297
|
+
pathPrefixes = Array.from(matches);
|
|
411
298
|
/*
|
|
412
299
|
Remove last one to avoid replacing with the already set
|
|
413
300
|
path.
|
|
414
301
|
*/
|
|
415
302
|
pathPrefixes.pop();
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
421
|
-
var pathPrefix = _step8.value;
|
|
422
|
-
if (index > 0) pathPrefixes[index] = (0, _path.resolve)(pathPrefixes[index - 1], pathPrefix);
|
|
423
|
-
index += 1;
|
|
424
|
-
}
|
|
425
|
-
} catch (err) {
|
|
426
|
-
_iterator8.e(err);
|
|
427
|
-
} finally {
|
|
428
|
-
_iterator8.f();
|
|
303
|
+
let index = 0;
|
|
304
|
+
for (const pathPrefix of pathPrefixes) {
|
|
305
|
+
if (index > 0) pathPrefixes[index] = resolve(pathPrefixes[index - 1], pathPrefix);
|
|
306
|
+
index += 1;
|
|
429
307
|
}
|
|
430
308
|
pathSuffix = targetPath.replace(/(?: ^|.*\/)node_modules\/(.+$)/, '$1');
|
|
431
309
|
} else {
|
|
432
|
-
pathPrefixes = [
|
|
310
|
+
pathPrefixes = [resolve(absoluteContextPath, 'node_modules')];
|
|
433
311
|
// Find longest common prefix.
|
|
434
|
-
|
|
435
|
-
while (
|
|
436
|
-
pathSuffix = targetPath.substring(
|
|
312
|
+
let index = 0;
|
|
313
|
+
while (index < absoluteContextPath.length && absoluteContextPath.charAt(index) === targetPath.charAt(index)) index += 1;
|
|
314
|
+
pathSuffix = targetPath.substring(index).replace(/^.*\/node_modules\//, '');
|
|
437
315
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
not always work.
|
|
456
|
-
*/
|
|
457
|
-
result.request = result.createData.rawRequest = result.createData.request = result.createData.resource = result.createData.userRequest = alternateTargetPath;
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
redundantRequest = {
|
|
461
|
-
path: alternateTargetPath,
|
|
462
|
-
version: otherPackageDescriptor.configuration.version
|
|
463
|
-
};
|
|
316
|
+
let redundantRequest = null;
|
|
317
|
+
for (const pathPrefix of pathPrefixes) {
|
|
318
|
+
const alternateTargetPath = resolve(pathPrefix, pathSuffix);
|
|
319
|
+
if (isFileSync(alternateTargetPath)) {
|
|
320
|
+
const otherPackageDescriptor = getClosestPackageDescriptor(alternateTargetPath);
|
|
321
|
+
if (otherPackageDescriptor) {
|
|
322
|
+
if (packageDescriptor.configuration.version === otherPackageDescriptor.configuration.version) {
|
|
323
|
+
log.info('\nConsolidate module request', `"${targetPath}" to`, `"${alternateTargetPath}".`);
|
|
324
|
+
/*
|
|
325
|
+
NOTE: Only overwriting
|
|
326
|
+
"result.createData.resource" like
|
|
327
|
+
implemented in
|
|
328
|
+
"NormaleModuleReplacementPlugin" does
|
|
329
|
+
not always work.
|
|
330
|
+
*/
|
|
331
|
+
result.request = result.createData.rawRequest = result.createData.request = result.createData.resource = result.createData.userRequest = alternateTargetPath;
|
|
332
|
+
return;
|
|
464
333
|
}
|
|
334
|
+
redundantRequest = {
|
|
335
|
+
path: alternateTargetPath,
|
|
336
|
+
version: otherPackageDescriptor.configuration.version
|
|
337
|
+
};
|
|
465
338
|
}
|
|
466
339
|
}
|
|
467
|
-
} catch (err) {
|
|
468
|
-
_iterator9.e(err);
|
|
469
|
-
} finally {
|
|
470
|
-
_iterator9.f();
|
|
471
340
|
}
|
|
472
|
-
if (redundantRequest) log.warn('\nIncluding different versions of same package', "
|
|
341
|
+
if (redundantRequest) log.warn('\nIncluding different versions of same package', `"${packageDescriptor.configuration.name}". Module`, `"${targetPath}" (version`, `${packageDescriptor.configuration.version}) has`, `redundancies with "${redundantRequest.path}"`, `(version ${redundantRequest.version}).`);
|
|
473
342
|
}
|
|
474
343
|
}
|
|
475
344
|
};
|
|
476
345
|
pluginInstances.push({
|
|
477
|
-
apply:
|
|
478
|
-
compiler.hooks.normalModuleFactory.tap('WebOptimizerModuleConsolidation',
|
|
346
|
+
apply: compiler => {
|
|
347
|
+
compiler.hooks.normalModuleFactory.tap('WebOptimizerModuleConsolidation', nmf => {
|
|
479
348
|
nmf.hooks.afterResolve.tap('WebOptimizerModuleConsolidation', consolidator);
|
|
480
349
|
});
|
|
481
350
|
}
|
|
@@ -566,77 +435,58 @@ new NormalModuleReplacementPlugin(
|
|
|
566
435
|
//// endregion
|
|
567
436
|
/// endregion
|
|
568
437
|
/// region loader helper
|
|
569
|
-
|
|
570
|
-
filePath =
|
|
571
|
-
return
|
|
572
|
-
return (0, _path.resolve)(configuration.path.context, filePath);
|
|
573
|
-
}).filter(function (filePath) {
|
|
574
|
-
return !configuration.path.context.startsWith(filePath);
|
|
575
|
-
}));
|
|
438
|
+
const isFilePathInDependencies = filePath => {
|
|
439
|
+
filePath = stripLoader(filePath);
|
|
440
|
+
return isFilePathInLocation(filePath, configuration.path.ignore.concat(module.directoryNames, configuration.loader.directoryNames).map(filePath => resolve(configuration.path.context, filePath)).filter(filePath => !configuration.path.context.startsWith(filePath)));
|
|
576
441
|
};
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
configuration
|
|
580
|
-
isFilePathInDependencies
|
|
581
|
-
loader
|
|
582
|
-
require: currentRequire
|
|
442
|
+
const loader = {};
|
|
443
|
+
const scope = {
|
|
444
|
+
configuration,
|
|
445
|
+
isFilePathInDependencies,
|
|
446
|
+
loader,
|
|
447
|
+
require: currentRequire ?? require
|
|
583
448
|
};
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
449
|
+
const evaluateAnThrow = (object, givenOptions = {}) => {
|
|
450
|
+
const options = {
|
|
451
|
+
filePath: configuration.path.context,
|
|
452
|
+
...givenOptions
|
|
453
|
+
};
|
|
589
454
|
if (typeof object === 'string') {
|
|
590
|
-
|
|
591
|
-
filePath: options.filePath
|
|
592
|
-
|
|
455
|
+
const evaluated = evaluate(object, {
|
|
456
|
+
filePath: options.filePath,
|
|
457
|
+
...scope,
|
|
593
458
|
type: options.type
|
|
594
|
-
})
|
|
459
|
+
});
|
|
595
460
|
if (evaluated.error) throw new Error('Error occurred during processing given expression: ' + evaluated.error);
|
|
596
461
|
return evaluated.result;
|
|
597
462
|
}
|
|
598
463
|
return object;
|
|
599
464
|
};
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
include: loaderConfiguration.include && evaluateAnThrow(loaderConfiguration.include) || configuration.path.source.base,
|
|
615
|
-
test: new RegExp(evaluateAnThrow(loaderConfiguration.test)),
|
|
616
|
-
use: evaluateAnThrow(loaderConfiguration.use)
|
|
617
|
-
};
|
|
618
|
-
};
|
|
619
|
-
var getIncludingPaths = function getIncludingPaths(path) {
|
|
620
|
-
return (0, _helper.normalizePaths)([path].concat(_module.locations.directoryPaths));
|
|
621
|
-
};
|
|
622
|
-
var postCSSResolver = function postCSSResolver(name, _context) {
|
|
623
|
-
for (var _i7 = 0, _Object$entries6 = Object.entries(configuration.module.aliases); _i7 < _Object$entries6.length; _i7++) {
|
|
624
|
-
var _Object$entries6$_i = (0, _slicedToArray2["default"])(_Object$entries6[_i7], 2),
|
|
625
|
-
source = _Object$entries6$_i[0],
|
|
626
|
-
target = _Object$entries6$_i[1];
|
|
627
|
-
if (source.startsWith(name)) return target;
|
|
628
|
-
}
|
|
465
|
+
const createEvaluateMapper = type => value => evaluateAnThrow(value, {
|
|
466
|
+
type
|
|
467
|
+
});
|
|
468
|
+
const evaluateAdditionalLoaderConfiguration = loaderConfiguration => ({
|
|
469
|
+
exclude: filePath => evaluateAnThrow(loaderConfiguration.exclude, {
|
|
470
|
+
filePath
|
|
471
|
+
}),
|
|
472
|
+
include: loaderConfiguration.include && evaluateAnThrow(loaderConfiguration.include) || configuration.path.source.base,
|
|
473
|
+
test: new RegExp(evaluateAnThrow(loaderConfiguration.test)),
|
|
474
|
+
use: evaluateAnThrow(loaderConfiguration.use)
|
|
475
|
+
});
|
|
476
|
+
const getIncludingPaths = path => normalizePaths([path].concat(module.locations.directoryPaths));
|
|
477
|
+
const postCSSResolver = (name, _context) => {
|
|
478
|
+
for (const [source, target] of Object.entries(configuration.module.aliases)) if (source.startsWith(name)) return target;
|
|
629
479
|
return name;
|
|
630
480
|
};
|
|
631
|
-
|
|
632
|
-
loader:
|
|
633
|
-
options:
|
|
481
|
+
const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(createEvaluateMapper('css')).concat({
|
|
482
|
+
loader: module.style.loader,
|
|
483
|
+
options: module.style.options || {}
|
|
634
484
|
}, {
|
|
635
|
-
loader:
|
|
636
|
-
options:
|
|
637
|
-
},
|
|
638
|
-
loader:
|
|
639
|
-
options:
|
|
485
|
+
loader: module.cascadingStyleSheet.loader,
|
|
486
|
+
options: module.cascadingStyleSheet.options || {}
|
|
487
|
+
}, module.preprocessor.cascadingStyleSheet.loader ? {
|
|
488
|
+
loader: module.preprocessor.cascadingStyleSheet.loader,
|
|
489
|
+
options: extend(true, optionalRequire('postcss') ? {
|
|
640
490
|
postcssOptions: {
|
|
641
491
|
/*
|
|
642
492
|
NOTE: Some plugins like "postcss-import" are
|
|
@@ -646,7 +496,7 @@ var cssUse = _module.preprocessor.cascadingStyleSheet.additional.pre.map(createE
|
|
|
646
496
|
plugins: [].concat(postcssImport ? postcssImport({
|
|
647
497
|
root: configuration.path.context,
|
|
648
498
|
resolve: postCSSResolver
|
|
649
|
-
}) : [],
|
|
499
|
+
}) : [], module.preprocessor.cascadingStyleSheet.additional.plugins.pre.map(createEvaluateMapper('css.postcss')),
|
|
650
500
|
/*
|
|
651
501
|
NOTE: Checking path doesn't work if fonts
|
|
652
502
|
are referenced in libraries provided in
|
|
@@ -664,14 +514,10 @@ var cssUse = _module.preprocessor.cascadingStyleSheet.additional.pre.map(createE
|
|
|
664
514
|
}]
|
|
665
515
|
}) : [], postcssURL ? postcssURL({
|
|
666
516
|
url: 'rebase'
|
|
667
|
-
}) : [], postcssSprites ? postcssSprites(
|
|
668
|
-
filterBy:
|
|
669
|
-
return configuration.files.compose.image ? Promise.resolve() : Promise.reject(new Error());
|
|
670
|
-
},
|
|
517
|
+
}) : [], postcssSprites ? postcssSprites({
|
|
518
|
+
filterBy: () => configuration.files.compose.image ? Promise.resolve() : Promise.reject(new Error()),
|
|
671
519
|
hooks: {
|
|
672
|
-
onSaveSpritesheet:
|
|
673
|
-
return (0, _path.join)(image.spritePath, (0, _path.relative)(configuration.path.target.asset.image, configuration.files.compose.image));
|
|
674
|
-
},
|
|
520
|
+
onSaveSpritesheet: image => join(image.spritePath, relative(configuration.path.target.asset.image, configuration.files.compose.image)),
|
|
675
521
|
/*
|
|
676
522
|
Reset this token due to a
|
|
677
523
|
sprite bug with
|
|
@@ -679,7 +525,7 @@ var cssUse = _module.preprocessor.cascadingStyleSheet.additional.pre.map(createE
|
|
|
679
525
|
which do not refer to an image
|
|
680
526
|
(e.g. linear gradient instead).
|
|
681
527
|
*/
|
|
682
|
-
onUpdateRule:
|
|
528
|
+
onUpdateRule: (rule, token, image) => {
|
|
683
529
|
if (updateRule) if (token.value.includes(token.text)) updateRule(rule, token, image);else token.cloneAfter({
|
|
684
530
|
type: 'decl',
|
|
685
531
|
prop: 'background-' + 'image',
|
|
@@ -688,157 +534,120 @@ var cssUse = _module.preprocessor.cascadingStyleSheet.additional.pre.map(createE
|
|
|
688
534
|
}
|
|
689
535
|
},
|
|
690
536
|
stylesheetPath: configuration.path.source.asset.cascadingStyleSheet,
|
|
691
|
-
spritePath: configuration.path.source.asset.image
|
|
692
|
-
|
|
537
|
+
spritePath: configuration.path.source.asset.image,
|
|
538
|
+
...configuration.imageSprite
|
|
539
|
+
}) : [], module.preprocessor.cascadingStyleSheet.additional.plugins.post.map(createEvaluateMapper('css.postcss')), module.optimizer.cssnano && postcssCSSnano ? postcssCSSnano(module.optimizer.cssnano) : [])
|
|
693
540
|
}
|
|
694
|
-
} : {},
|
|
695
|
-
} : [],
|
|
696
|
-
|
|
541
|
+
} : {}, module.preprocessor.cascadingStyleSheet.options || {})
|
|
542
|
+
} : [], module.preprocessor.cascadingStyleSheet.additional.post.map(createEvaluateMapper('css')));
|
|
543
|
+
const genericLoader = {
|
|
697
544
|
// Convert to compatible native web types.
|
|
698
545
|
// region generic template
|
|
699
546
|
ejs: {
|
|
700
|
-
exclude:
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
})).includes(filePath) || _module.preprocessor.ejs.exclude === null ? false : evaluateAnThrow(_module.preprocessor.ejs.exclude, {
|
|
704
|
-
filePath: filePath
|
|
705
|
-
});
|
|
706
|
-
},
|
|
547
|
+
exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || module.preprocessor.ejs.exclude === null ? false : evaluateAnThrow(module.preprocessor.ejs.exclude, {
|
|
548
|
+
filePath
|
|
549
|
+
}),
|
|
707
550
|
include: getIncludingPaths(configuration.path.source.asset.template),
|
|
708
551
|
test: /^(?!.+\.html\.ejs$).+\.ejs$/i,
|
|
709
|
-
use:
|
|
710
|
-
loader:
|
|
711
|
-
options:
|
|
552
|
+
use: module.preprocessor.ejs.additional.pre.map(createEvaluateMapper('ejs')).concat({
|
|
553
|
+
loader: module.preprocessor.ejs.loader,
|
|
554
|
+
options: extend(true, module.preprocessor.ejs.options || {}, {
|
|
712
555
|
compress: {
|
|
713
556
|
html: false
|
|
714
557
|
}
|
|
715
558
|
})
|
|
716
|
-
},
|
|
559
|
+
}, module.preprocessor.ejs.additional.post.map(createEvaluateMapper('ejs')))
|
|
717
560
|
},
|
|
718
561
|
// endregion
|
|
719
562
|
// region script
|
|
720
563
|
script: {
|
|
721
|
-
exclude:
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
var result = evaluateAnThrow(_module.preprocessor.javaScript.include, {
|
|
729
|
-
filePath: filePath,
|
|
564
|
+
exclude: filePath => evaluateAnThrow(module.preprocessor.javaScript.exclude, {
|
|
565
|
+
filePath,
|
|
566
|
+
type: 'script'
|
|
567
|
+
}),
|
|
568
|
+
include: filePath => {
|
|
569
|
+
const result = evaluateAnThrow(module.preprocessor.javaScript.include, {
|
|
570
|
+
filePath,
|
|
730
571
|
type: 'script'
|
|
731
572
|
});
|
|
732
573
|
if ([null, undefined].includes(result)) {
|
|
733
|
-
|
|
734
|
-
_step0;
|
|
735
|
-
try {
|
|
736
|
-
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
737
|
-
var includePath = _step0.value;
|
|
738
|
-
if (filePath.startsWith(includePath)) return true;
|
|
739
|
-
}
|
|
740
|
-
} catch (err) {
|
|
741
|
-
_iterator0.e(err);
|
|
742
|
-
} finally {
|
|
743
|
-
_iterator0.f();
|
|
744
|
-
}
|
|
574
|
+
for (const includePath of getIncludingPaths(configuration.path.source.asset.javaScript)) if (filePath.startsWith(includePath)) return true;
|
|
745
575
|
return false;
|
|
746
576
|
}
|
|
747
577
|
return Boolean(result);
|
|
748
578
|
},
|
|
749
|
-
test: new RegExp(
|
|
750
|
-
use:
|
|
751
|
-
loader:
|
|
752
|
-
options:
|
|
753
|
-
},
|
|
579
|
+
test: new RegExp(module.preprocessor.javaScript.regularExpression, 'i'),
|
|
580
|
+
use: module.preprocessor.javaScript.additional.pre.map(createEvaluateMapper('script')).concat({
|
|
581
|
+
loader: module.preprocessor.javaScript.loader,
|
|
582
|
+
options: module.preprocessor.javaScript.options || {}
|
|
583
|
+
}, module.preprocessor.javaScript.additional.post.map(createEvaluateMapper('script')))
|
|
754
584
|
},
|
|
755
585
|
// endregion
|
|
756
586
|
// region html template
|
|
757
587
|
html: {
|
|
758
588
|
// NOTE: This is only for the main entry template.
|
|
759
589
|
main: {
|
|
760
|
-
test: new RegExp('^' +
|
|
590
|
+
test: new RegExp('^' + escapeRegularExpressions(configuration.files.defaultHTML.template.filePath) + '(?:\\?.*)?$'),
|
|
761
591
|
use: configuration.files.defaultHTML.template.use
|
|
762
592
|
},
|
|
763
593
|
ejs: {
|
|
764
|
-
exclude:
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
filePath: filePath,
|
|
769
|
-
type: 'html.ejs'
|
|
770
|
-
}));
|
|
771
|
-
},
|
|
594
|
+
exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.preprocessor.html.exclude === null ? false : evaluateAnThrow(module.preprocessor.html.exclude, {
|
|
595
|
+
filePath,
|
|
596
|
+
type: 'html.ejs'
|
|
597
|
+
})),
|
|
772
598
|
include: configuration.path.source.asset.template,
|
|
773
599
|
test: /\.html\.ejs(?:\?.*)?$/i,
|
|
774
|
-
use:
|
|
600
|
+
use: module.preprocessor.html.additional.pre.map(createEvaluateMapper('html.ejs')).concat(
|
|
775
601
|
/*
|
|
776
602
|
We might need to evaluate ejs before we are able to
|
|
777
603
|
parse html beforhand. If not we parse it as html
|
|
778
604
|
directly.
|
|
779
605
|
*/
|
|
780
606
|
|
|
781
|
-
(
|
|
607
|
+
(isPlainObject(module.preprocessor.html.options) ? module.preprocessor.html.options : {
|
|
782
608
|
compileSteps: 2
|
|
783
609
|
}).compileSteps % 2 ? [] : [{
|
|
784
610
|
loader: 'extract'
|
|
785
611
|
}, {
|
|
786
|
-
loader:
|
|
787
|
-
options:
|
|
612
|
+
loader: module.html.loader,
|
|
613
|
+
options: module.html.options || {}
|
|
788
614
|
}], {
|
|
789
|
-
loader:
|
|
790
|
-
options:
|
|
791
|
-
},
|
|
615
|
+
loader: module.preprocessor.html.loader,
|
|
616
|
+
options: module.preprocessor.html.options || {}
|
|
617
|
+
}, module.preprocessor.html.additional.post.map(createEvaluateMapper('html.ejs')))
|
|
792
618
|
},
|
|
793
619
|
html: {
|
|
794
|
-
exclude:
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
filePath: filePath,
|
|
799
|
-
type: 'html'
|
|
800
|
-
}));
|
|
801
|
-
},
|
|
620
|
+
exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.html.exclude === null ? true : evaluateAnThrow(module.html.exclude, {
|
|
621
|
+
filePath,
|
|
622
|
+
type: 'html'
|
|
623
|
+
})),
|
|
802
624
|
include: configuration.path.source.asset.template,
|
|
803
625
|
test: /\.html(?:\?.*)?$/i,
|
|
804
|
-
use:
|
|
805
|
-
loader: 'file?name=' +
|
|
626
|
+
use: module.html.additional.pre.map(createEvaluateMapper('html')).concat({
|
|
627
|
+
loader: 'file?name=' + join(relative(configuration.path.target.base, configuration.path.target.asset.template), `[name][ext]?${configuration.hashAlgorithm}=` + '[contenthash]')
|
|
806
628
|
}, {
|
|
807
629
|
loader: 'extract'
|
|
808
630
|
}, {
|
|
809
|
-
loader:
|
|
810
|
-
options:
|
|
811
|
-
},
|
|
631
|
+
loader: module.html.loader,
|
|
632
|
+
options: module.html.options || {}
|
|
633
|
+
}, module.html.additional.post.map(createEvaluateMapper('html')))
|
|
812
634
|
}
|
|
813
635
|
},
|
|
814
636
|
// endregion
|
|
815
637
|
// Load dependencies.
|
|
816
638
|
// region style
|
|
817
639
|
style: {
|
|
818
|
-
exclude:
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
var result = evaluateAnThrow(_module.cascadingStyleSheet.include, {
|
|
826
|
-
filePath: filePath,
|
|
640
|
+
exclude: filePath => module.cascadingStyleSheet.exclude === null ? isFilePathInDependencies(filePath) : evaluateAnThrow(module.cascadingStyleSheet.exclude, {
|
|
641
|
+
filePath,
|
|
642
|
+
type: 'style'
|
|
643
|
+
}),
|
|
644
|
+
include: filePath => {
|
|
645
|
+
const result = evaluateAnThrow(module.cascadingStyleSheet.include, {
|
|
646
|
+
filePath,
|
|
827
647
|
type: 'style'
|
|
828
648
|
});
|
|
829
649
|
if ([null, undefined].includes(result)) {
|
|
830
|
-
|
|
831
|
-
_step1;
|
|
832
|
-
try {
|
|
833
|
-
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
834
|
-
var includePath = _step1.value;
|
|
835
|
-
if (filePath.startsWith(includePath)) return true;
|
|
836
|
-
}
|
|
837
|
-
} catch (err) {
|
|
838
|
-
_iterator1.e(err);
|
|
839
|
-
} finally {
|
|
840
|
-
_iterator1.f();
|
|
841
|
-
}
|
|
650
|
+
for (const includePath of getIncludingPaths(configuration.path.source.asset.cascadingStyleSheet)) if (filePath.startsWith(includePath)) return true;
|
|
842
651
|
return false;
|
|
843
652
|
}
|
|
844
653
|
return Boolean(result);
|
|
@@ -851,14 +660,12 @@ var genericLoader = {
|
|
|
851
660
|
// region font
|
|
852
661
|
font: {
|
|
853
662
|
eot: {
|
|
854
|
-
exclude:
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
});
|
|
859
|
-
},
|
|
663
|
+
exclude: filePath => module.optimizer.font.eot.exclude === null ? false : evaluateAnThrow(module.optimizer.font.eot.exclude, {
|
|
664
|
+
filePath,
|
|
665
|
+
type: 'font.eot'
|
|
666
|
+
}),
|
|
860
667
|
generator: {
|
|
861
|
-
filename:
|
|
668
|
+
filename: join(relative(configuration.path.target.base, configuration.path.target.asset.font), '[name][ext]') + `?${configuration.hashAlgorithm}=[contenthash]`
|
|
862
669
|
},
|
|
863
670
|
test: /\.eot(?: \?.*)?$/i,
|
|
864
671
|
type: 'asset/resource',
|
|
@@ -867,18 +674,16 @@ var genericLoader = {
|
|
|
867
674
|
maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
|
|
868
675
|
}
|
|
869
676
|
},
|
|
870
|
-
use:
|
|
677
|
+
use: module.optimizer.font.eot.loader.map(createEvaluateMapper('font.eot'))
|
|
871
678
|
},
|
|
872
679
|
svg: {
|
|
873
|
-
exclude:
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
});
|
|
878
|
-
},
|
|
680
|
+
exclude: filePath => module.optimizer.font.svg.exclude === null ? false : evaluateAnThrow(module.optimizer.font.svg.exclude, {
|
|
681
|
+
filePath,
|
|
682
|
+
type: 'svg'
|
|
683
|
+
}),
|
|
879
684
|
include: configuration.path.source.asset.font,
|
|
880
685
|
generator: {
|
|
881
|
-
filename:
|
|
686
|
+
filename: join(relative(configuration.path.target.base, configuration.path.target.asset.font), '[name][ext]') + `?${configuration.hashAlgorithm}=[contenthash]`
|
|
882
687
|
},
|
|
883
688
|
mimetype: 'image/svg+xml',
|
|
884
689
|
parser: {
|
|
@@ -888,17 +693,15 @@ var genericLoader = {
|
|
|
888
693
|
},
|
|
889
694
|
test: /\.svg(?: \?.*)?$/i,
|
|
890
695
|
type: 'asset/resource',
|
|
891
|
-
use:
|
|
696
|
+
use: module.optimizer.font.svg.loader.map(createEvaluateMapper('font.svg'))
|
|
892
697
|
},
|
|
893
698
|
ttf: {
|
|
894
|
-
exclude:
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
});
|
|
899
|
-
},
|
|
699
|
+
exclude: filePath => module.optimizer.font.ttf.exclude === null ? false : evaluateAnThrow(module.optimizer.font.ttf.exclude, {
|
|
700
|
+
filePath,
|
|
701
|
+
type: 'ttf'
|
|
702
|
+
}),
|
|
900
703
|
generator: {
|
|
901
|
-
filename:
|
|
704
|
+
filename: join(relative(configuration.path.target.base, configuration.path.target.asset.font), '[name][ext]') + `?${configuration.hashAlgorithm}=[contenthash]`
|
|
902
705
|
},
|
|
903
706
|
test: /\.ttf(?: \?.*)?$/i,
|
|
904
707
|
type: 'asset/resource',
|
|
@@ -908,17 +711,15 @@ var genericLoader = {
|
|
|
908
711
|
maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
|
|
909
712
|
}
|
|
910
713
|
},
|
|
911
|
-
use:
|
|
714
|
+
use: module.optimizer.font.ttf.loader.map(createEvaluateMapper('font.ttf'))
|
|
912
715
|
},
|
|
913
716
|
woff: {
|
|
914
|
-
exclude:
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
});
|
|
919
|
-
},
|
|
717
|
+
exclude: filePath => module.optimizer.font.woff.exclude === null ? false : evaluateAnThrow(module.optimizer.font.woff.exclude, {
|
|
718
|
+
filePath,
|
|
719
|
+
type: 'woff'
|
|
720
|
+
}),
|
|
920
721
|
generator: {
|
|
921
|
-
filename:
|
|
722
|
+
filename: join(relative(configuration.path.target.base, configuration.path.target.asset.font), '[name][ext]') + `?${configuration.hashAlgorithm}=[contenthash]`
|
|
922
723
|
},
|
|
923
724
|
test: /\.woff2?(?: \?.*)?$/i,
|
|
924
725
|
type: 'asset/resource',
|
|
@@ -927,20 +728,18 @@ var genericLoader = {
|
|
|
927
728
|
maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
|
|
928
729
|
}
|
|
929
730
|
},
|
|
930
|
-
use:
|
|
731
|
+
use: module.optimizer.font.woff.loader.map(createEvaluateMapper('font.woff'))
|
|
931
732
|
}
|
|
932
733
|
},
|
|
933
734
|
// endregion
|
|
934
735
|
// region image
|
|
935
736
|
image: {
|
|
936
|
-
exclude:
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
});
|
|
941
|
-
},
|
|
737
|
+
exclude: filePath => module.optimizer.image.exclude === null ? isFilePathInDependencies(filePath) : evaluateAnThrow(module.optimizer.image.exclude, {
|
|
738
|
+
filePath,
|
|
739
|
+
type: 'image'
|
|
740
|
+
}),
|
|
942
741
|
generator: {
|
|
943
|
-
filename: typeof configuration.path.target.asset.image === 'string' ?
|
|
742
|
+
filename: typeof configuration.path.target.asset.image === 'string' ? join(relative(configuration.path.target.base, configuration.path.target.asset.image), '[name][ext]') + `?${configuration.hashAlgorithm}=[contenthash]` : configuration.path.target.asset.image
|
|
944
743
|
},
|
|
945
744
|
include: configuration.path.source.asset.image,
|
|
946
745
|
test: /\.(?: gif|ico|jpg|png|svg)(?: \?.*)?$/i,
|
|
@@ -950,20 +749,20 @@ var genericLoader = {
|
|
|
950
749
|
maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
|
|
951
750
|
}
|
|
952
751
|
},
|
|
953
|
-
use:
|
|
752
|
+
use: module.optimizer.image.loader.map(createEvaluateMapper('image'))
|
|
954
753
|
},
|
|
955
754
|
// endregion
|
|
956
755
|
// region data
|
|
957
756
|
data: {
|
|
958
|
-
exclude:
|
|
757
|
+
exclude: filePath => {
|
|
959
758
|
if (typeof filePath !== 'string') return false;
|
|
960
|
-
return configuration.extensions.file.internal.includes(
|
|
961
|
-
filePath
|
|
759
|
+
return configuration.extensions.file.internal.includes(extname(stripLoader(filePath))) || (module.optimizer.data.exclude === null ? isFilePathInDependencies(filePath) : evaluateAnThrow(module.optimizer.data.exclude, {
|
|
760
|
+
filePath,
|
|
962
761
|
type: 'data'
|
|
963
762
|
}));
|
|
964
763
|
},
|
|
965
764
|
generator: {
|
|
966
|
-
filename:
|
|
765
|
+
filename: join(relative(configuration.path.target.base, configuration.path.target.asset.data), '[name][ext]') + `?${configuration.hashAlgorithm}=[contenthash]`
|
|
967
766
|
},
|
|
968
767
|
test: /.+/,
|
|
969
768
|
type: 'asset/resource',
|
|
@@ -972,11 +771,11 @@ var genericLoader = {
|
|
|
972
771
|
maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
|
|
973
772
|
}
|
|
974
773
|
},
|
|
975
|
-
use:
|
|
774
|
+
use: module.optimizer.data.loader.map(createEvaluateMapper('data'))
|
|
976
775
|
}
|
|
977
776
|
// endregion
|
|
978
777
|
};
|
|
979
|
-
|
|
778
|
+
extend(loader, genericLoader);
|
|
980
779
|
if (configuration.files.compose.cascadingStyleSheet && plugins.MiniCSSExtract) {
|
|
981
780
|
/*
|
|
982
781
|
NOTE: We have to remove the client side javascript hmr style loader
|
|
@@ -995,59 +794,50 @@ if (configuration.files.compose.cascadingStyleSheet && plugins.MiniCSSExtract) {
|
|
|
995
794
|
So we inject live reload and hot module replacement manually.
|
|
996
795
|
*/
|
|
997
796
|
if (htmlAvailable && configuration.debug && configuration.development.server.liveReload && !Object.prototype.hasOwnProperty.call(configuration.injection.entry.normalized, 'developmentHandler') && (configuration.development.includeClient || typeof configuration.development.includeClient !== 'boolean' && ['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2]))) {
|
|
998
|
-
configuration.injection.entry.normalized.developmentHandler = ['webpack-dev-server/client/index.js?' + 'live-reload=true' +
|
|
797
|
+
configuration.injection.entry.normalized.developmentHandler = ['webpack-dev-server/client/index.js?' + 'live-reload=true' + `&hot=${configuration.development.server.hot ? 'true' : 'false'}` + `&http${configuration.development.server.https ? 's' : ''}://` + `${configuration.development.server.host}: ` + String(configuration.development.server.port)];
|
|
999
798
|
if (configuration.development.server.hot) {
|
|
1000
799
|
configuration.injection.entry.normalized.developmentHandler.push('webpack/hot/dev-server.js');
|
|
1001
800
|
configuration.development.server.hot = false;
|
|
1002
|
-
pluginInstances.push(new
|
|
801
|
+
pluginInstances.push(new HotModuleReplacementPlugin());
|
|
1003
802
|
}
|
|
1004
803
|
}
|
|
1005
804
|
/// endregion
|
|
1006
805
|
// endregion
|
|
1007
806
|
// region plugins
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1012
|
-
var pluginConfiguration = _step10.value;
|
|
1013
|
-
var _plugin = optionalRequire(pluginConfiguration.name.module);
|
|
1014
|
-
if (_plugin) pluginInstances.push((0, _construct2["default"])(_plugin[pluginConfiguration.name.initializer], (0, _toConsumableArray2["default"])(pluginConfiguration.parameters)));else log.warn("Configured plugin module \"".concat(pluginConfiguration.name.module, "\""), 'could not be loaded.');
|
|
1015
|
-
}
|
|
1016
|
-
// endregion
|
|
1017
|
-
// region minimizer and image compression
|
|
1018
|
-
// NOTE: This plugin should be loaded at last to ensure that all emitted images
|
|
1019
|
-
// ran through.
|
|
1020
|
-
} catch (err) {
|
|
1021
|
-
_iterator10.e(err);
|
|
1022
|
-
} finally {
|
|
1023
|
-
_iterator10.f();
|
|
807
|
+
for (const pluginConfiguration of configuration.plugins) {
|
|
808
|
+
const plugin = optionalRequire(pluginConfiguration.name.module);
|
|
809
|
+
if (plugin) pluginInstances.push(new plugin[pluginConfiguration.name.initializer](...pluginConfiguration.parameters));else log.warn(`Configured plugin module "${pluginConfiguration.name.module}"`, 'could not be loaded.');
|
|
1024
810
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
811
|
+
// endregion
|
|
812
|
+
// region minimizer and image compression
|
|
813
|
+
// NOTE: This plugin should be loaded at last to ensure that all emitted images
|
|
814
|
+
// ran through.
|
|
815
|
+
if (!module.optimizer.minimizer) {
|
|
816
|
+
module.optimizer.minimizer = [];
|
|
817
|
+
if (plugins.Terser) module.optimizer.minimizer.push(new plugins.Terser({
|
|
1028
818
|
extractComments: false,
|
|
1029
819
|
parallel: true
|
|
1030
820
|
}));
|
|
1031
|
-
if (plugins.ImageMinimizer)
|
|
821
|
+
if (plugins.ImageMinimizer) module.optimizer.minimizer.push(new plugins.ImageMinimizer(extend(true, {
|
|
1032
822
|
minimizer: {
|
|
1033
823
|
implementation: plugins.ImageMinimizer.imageminMinify
|
|
1034
824
|
}
|
|
1035
|
-
},
|
|
825
|
+
}, module.optimizer.image.content)));
|
|
1036
826
|
}
|
|
1037
827
|
// endregion
|
|
1038
828
|
// region configuration
|
|
1039
|
-
|
|
829
|
+
let customConfiguration = {};
|
|
1040
830
|
if (configuration.path.configuration.json) try {
|
|
1041
831
|
require.resolve(configuration.path.configuration.json);
|
|
1042
832
|
try {
|
|
1043
833
|
customConfiguration = currentRequire(configuration.path.configuration.json);
|
|
1044
834
|
} catch (error) {
|
|
1045
|
-
log.debug('Importing provided json webpack configuration file path',
|
|
835
|
+
log.debug('Importing provided json webpack configuration file path', `under "${configuration.path.configuration.json}" failed:`, represent(error));
|
|
1046
836
|
}
|
|
1047
|
-
} catch
|
|
1048
|
-
log.debug('Optional configuration file', "
|
|
837
|
+
} catch {
|
|
838
|
+
log.debug('Optional configuration file', `"${configuration.path.configuration.json}" not available.`);
|
|
1049
839
|
}
|
|
1050
|
-
|
|
840
|
+
export let webpackConfiguration = extend(true, {
|
|
1051
841
|
bail: !configuration.givenCommandLineArguments.includes('--watch'),
|
|
1052
842
|
context: configuration.path.context,
|
|
1053
843
|
devtool: configuration.development.tool,
|
|
@@ -1059,29 +849,29 @@ var webpackConfiguration = exports.webpackConfiguration = (0, _clientnode.extend
|
|
|
1059
849
|
entry: configuration.injection.entry.normalized,
|
|
1060
850
|
externals: configuration.injection.external.modules,
|
|
1061
851
|
resolve: {
|
|
1062
|
-
alias:
|
|
1063
|
-
aliasFields: configuration
|
|
852
|
+
alias: module.aliases,
|
|
853
|
+
aliasFields: configuration.package.aliasPropertyNames,
|
|
1064
854
|
extensions: configuration.extensions.file.internal,
|
|
1065
|
-
mainFields: configuration
|
|
1066
|
-
mainFiles: configuration
|
|
1067
|
-
modules:
|
|
1068
|
-
symlinks:
|
|
1069
|
-
unsafeCache: Boolean(
|
|
855
|
+
mainFields: configuration.package.main.propertyNames,
|
|
856
|
+
mainFiles: configuration.package.main.fileNames,
|
|
857
|
+
modules: normalizePaths(module.directoryNames),
|
|
858
|
+
symlinks: module.resolveSymlinks,
|
|
859
|
+
unsafeCache: Boolean(configuration.cache?.unsafe ?? configuration.cache?.main)
|
|
1070
860
|
},
|
|
1071
861
|
resolveLoader: {
|
|
1072
862
|
alias: configuration.loader.aliases,
|
|
1073
|
-
aliasFields: configuration
|
|
863
|
+
aliasFields: configuration.package.aliasPropertyNames,
|
|
1074
864
|
extensions: configuration.loader.extensions.file,
|
|
1075
|
-
mainFields: configuration
|
|
1076
|
-
mainFiles: configuration
|
|
865
|
+
mainFields: configuration.package.main.propertyNames,
|
|
866
|
+
mainFiles: configuration.package.main.fileNames,
|
|
1077
867
|
modules: configuration.loader.directoryNames,
|
|
1078
868
|
symlinks: configuration.loader.resolveSymlinks
|
|
1079
869
|
},
|
|
1080
870
|
// endregion
|
|
1081
871
|
// region output
|
|
1082
872
|
output: {
|
|
1083
|
-
assetModuleFilename:
|
|
1084
|
-
filename:
|
|
873
|
+
assetModuleFilename: join(relative(configuration.path.target.base, configuration.path.target.asset.base), '[name][ext]') + `?${configuration.hashAlgorithm}=[chunkhash]`,
|
|
874
|
+
filename: relative(configuration.path.target.base, configuration.files.compose.javaScript),
|
|
1085
875
|
globalObject: configuration.exportFormat.globalObject,
|
|
1086
876
|
hashFunction: configuration.hashAlgorithm,
|
|
1087
877
|
library: {
|
|
@@ -1090,7 +880,7 @@ var webpackConfiguration = exports.webpackConfiguration = (0, _clientnode.extend
|
|
|
1090
880
|
umdNamedDefine: true
|
|
1091
881
|
},
|
|
1092
882
|
path: configuration.path.target.base,
|
|
1093
|
-
publicPath: configuration.path.target
|
|
883
|
+
publicPath: configuration.path.target.public
|
|
1094
884
|
},
|
|
1095
885
|
performance: configuration.performanceHints,
|
|
1096
886
|
/*
|
|
@@ -1102,27 +892,24 @@ var webpackConfiguration = exports.webpackConfiguration = (0, _clientnode.extend
|
|
|
1102
892
|
// endregion
|
|
1103
893
|
mode: configuration.debug ? 'development' : 'production',
|
|
1104
894
|
module: {
|
|
1105
|
-
rules:
|
|
895
|
+
rules: module.additional.pre.map(evaluateAdditionalLoaderConfiguration).concat(loader.ejs, loader.script, loader.html.main, loader.html.ejs, loader.html.html, loader.style, loader.font.eot, loader.font.svg, loader.font.ttf, loader.font.woff, loader.image, loader.data, module.additional.post.map(evaluateAdditionalLoaderConfiguration))
|
|
1106
896
|
},
|
|
1107
897
|
node: configuration.nodeEnvironment,
|
|
1108
|
-
optimization:
|
|
898
|
+
optimization: {
|
|
1109
899
|
chunkIds: configuration.debug ? 'named' : 'total-size',
|
|
1110
900
|
moduleIds: configuration.debug ? 'named' : 'size',
|
|
1111
901
|
// region common chunks
|
|
1112
|
-
splitChunks:
|
|
902
|
+
splitChunks: extend(true, !configuration.injection.chunks || configuration.targetTechnology.payload === 'node' || configuration.givenCommandLineArguments[2] === 'test' ? {
|
|
1113
903
|
cacheGroups: {
|
|
1114
|
-
|
|
904
|
+
default: false,
|
|
1115
905
|
defaultVendors: false
|
|
1116
906
|
}
|
|
1117
907
|
} : {
|
|
1118
908
|
chunks: 'all',
|
|
1119
909
|
cacheGroups: {
|
|
1120
910
|
defaultVendors: {
|
|
1121
|
-
chunks:
|
|
1122
|
-
if (configuration.inPlace.javaScript) for (
|
|
1123
|
-
var _name3 = _Object$keys[_i8];
|
|
1124
|
-
if (_name3 === '*' || _name3 === chunk.name) return false;
|
|
1125
|
-
}
|
|
911
|
+
chunks: chunk => {
|
|
912
|
+
if (configuration.inPlace.javaScript) for (const name of Object.keys(configuration.inPlace.javaScript)) if (name === '*' || name === chunk.name) return false;
|
|
1126
913
|
return true;
|
|
1127
914
|
},
|
|
1128
915
|
priority: -10,
|
|
@@ -1130,43 +917,45 @@ var webpackConfiguration = exports.webpackConfiguration = (0, _clientnode.extend
|
|
|
1130
917
|
test: /[\\/]node_modules[\\/]/
|
|
1131
918
|
}
|
|
1132
919
|
}
|
|
1133
|
-
}, configuration.injection.chunks)
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
920
|
+
}, configuration.injection.chunks),
|
|
921
|
+
// endregion
|
|
922
|
+
...mask(module.optimizer, {
|
|
923
|
+
exclude: {
|
|
924
|
+
babelMinify: true,
|
|
925
|
+
cssnano: true,
|
|
926
|
+
data: true,
|
|
927
|
+
font: true,
|
|
928
|
+
htmlMinifier: true,
|
|
929
|
+
image: true
|
|
930
|
+
}
|
|
931
|
+
})
|
|
932
|
+
},
|
|
1144
933
|
plugins: pluginInstances
|
|
1145
|
-
},
|
|
934
|
+
}, configuration.cache?.main ? {
|
|
1146
935
|
cache: configuration.cache.main
|
|
1147
936
|
} : {}, configuration.webpack, customConfiguration);
|
|
1148
|
-
if (configuration.nodeENV !== null) if (
|
|
937
|
+
if (configuration.nodeENV !== null) if (typeof webpackConfiguration.optimization === 'object') webpackConfiguration.optimization.nodeEnv = configuration.nodeENV;else webpackConfiguration.optimization = {
|
|
1149
938
|
nodeEnv: configuration.nodeENV
|
|
1150
939
|
};
|
|
1151
|
-
if (!Array.isArray(
|
|
1152
|
-
noParse:
|
|
940
|
+
if (!Array.isArray(module.skipParseRegularExpressions) || module.skipParseRegularExpressions.length) if (typeof webpackConfiguration.module === 'object') webpackConfiguration.module.noParse = module.skipParseRegularExpressions;else webpackConfiguration.module = {
|
|
941
|
+
noParse: module.skipParseRegularExpressions
|
|
1153
942
|
};
|
|
1154
943
|
if (configuration.path.configuration.javaScript) try {
|
|
1155
944
|
require.resolve(configuration.path.configuration.javaScript);
|
|
1156
|
-
|
|
1157
|
-
if (
|
|
1158
|
-
if (Object.prototype.hasOwnProperty.call(result, 'replaceWebOptimizer'))
|
|
1159
|
-
} else log.debug('Failed to load given JavaScript configuration file path', "
|
|
1160
|
-
} catch
|
|
1161
|
-
log.debug('Optional configuration file script', "
|
|
945
|
+
const result = optionalRequire(configuration.path.configuration.javaScript);
|
|
946
|
+
if (isPlainObject(result)) {
|
|
947
|
+
if (Object.prototype.hasOwnProperty.call(result, 'replaceWebOptimizer')) webpackConfiguration = result.replaceWebOptimizer;else extend(true, webpackConfiguration, result);
|
|
948
|
+
} else log.debug('Failed to load given JavaScript configuration file path', `"${configuration.path.configuration.javaScript}".`);
|
|
949
|
+
} catch {
|
|
950
|
+
log.debug('Optional configuration file script', `"${configuration.path.configuration.javaScript}" not available.`);
|
|
1162
951
|
}
|
|
1163
|
-
log.debug('Using internal configuration:',
|
|
952
|
+
log.debug('Using internal configuration:', util.inspect(configuration, {
|
|
1164
953
|
depth: null
|
|
1165
954
|
}));
|
|
1166
955
|
log.debug('-----------------------------------------------------------');
|
|
1167
|
-
log.debug('Using webpack configuration:',
|
|
956
|
+
log.debug('Using webpack configuration:', util.inspect(webpackConfiguration, {
|
|
1168
957
|
depth: null
|
|
1169
958
|
}));
|
|
1170
959
|
|
|
1171
960
|
// endregion
|
|
1172
|
-
|
|
961
|
+
export default webpackConfiguration;
|