webpack 3.3.0 → 3.5.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/README.md +34 -11
- package/bin/config-optimist.js +1 -0
- package/bin/config-yargs.js +12 -4
- package/bin/convert-argv.js +28 -8
- package/bin/webpack.js +198 -182
- package/lib/ContextModule.js +87 -13
- package/lib/DelegatedModule.js +10 -4
- package/lib/DelegatedModuleFactoryPlugin.js +5 -4
- package/lib/DelegatedPlugin.js +3 -0
- package/lib/DllReferencePlugin.js +3 -0
- package/lib/ExternalModule.js +6 -1
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/HotModuleReplacement.runtime.js +13 -5
- package/lib/MultiCompiler.js +2 -2
- package/lib/NormalModule.js +32 -9
- package/lib/NormalModuleFactory.js +133 -145
- package/lib/Parser.js +52 -58
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/SourceMapDevToolPlugin.js +57 -41
- package/lib/Stats.js +58 -24
- package/lib/Template.js +1 -1
- package/lib/dependencies/DelegatedExportsDependency.js +33 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +11 -4
- package/lib/dependencies/ImportPlugin.js +8 -0
- package/lib/dependencies/ImportWeakContextDependency.js +22 -0
- package/lib/dependencies/ImportWeakDependency.js +47 -0
- package/lib/dependencies/RequireContextDependency.js +5 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +9 -1
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +27 -33
- package/lib/optimize/AggressiveSplittingPlugin.js +46 -33
- package/lib/optimize/ChunkModuleIdRangePlugin.js +1 -3
- package/lib/optimize/CommonsChunkPlugin.js +11 -4
- package/lib/optimize/ConcatenatedModule.js +403 -229
- package/lib/optimize/ModuleConcatenationPlugin.js +30 -35
- package/lib/util/identifier.js +23 -1
- package/lib/webpack.js +52 -55
- package/package.json +10 -10
- package/schemas/webpackOptionsSchema.json +27 -12
@@ -17,6 +17,38 @@ const basename = (name) => {
|
|
17
17
|
return name.substr(name.lastIndexOf("/") + 1);
|
18
18
|
};
|
19
19
|
|
20
|
+
function getTaskForFile(file, chunk, options, compilation) {
|
21
|
+
const asset = compilation.assets[file];
|
22
|
+
if(asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
|
23
|
+
const data = asset.__SourceMapDevToolData;
|
24
|
+
for(const cachedFile in data) {
|
25
|
+
compilation.assets[cachedFile] = data[cachedFile];
|
26
|
+
if(cachedFile !== file)
|
27
|
+
chunk.files.push(cachedFile);
|
28
|
+
}
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
let source, sourceMap;
|
32
|
+
if(asset.sourceAndMap) {
|
33
|
+
const sourceAndMap = asset.sourceAndMap(options);
|
34
|
+
sourceMap = sourceAndMap.map;
|
35
|
+
source = sourceAndMap.source;
|
36
|
+
} else {
|
37
|
+
sourceMap = asset.map(options);
|
38
|
+
source = asset.source();
|
39
|
+
}
|
40
|
+
if(sourceMap) {
|
41
|
+
return {
|
42
|
+
chunk,
|
43
|
+
file,
|
44
|
+
asset,
|
45
|
+
source,
|
46
|
+
sourceMap,
|
47
|
+
modules: undefined
|
48
|
+
};
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
20
52
|
class SourceMapDevToolPlugin {
|
21
53
|
constructor(options) {
|
22
54
|
if(arguments.length > 1)
|
@@ -43,57 +75,41 @@ class SourceMapDevToolPlugin {
|
|
43
75
|
const requestShortener = new RequestShortener(compiler.context);
|
44
76
|
const options = this.options;
|
45
77
|
options.test = options.test || /\.(js|css)($|\?)/i;
|
78
|
+
|
79
|
+
const matchObject = ModuleFilenameHelpers.matchObject.bind(undefined, options);
|
80
|
+
|
46
81
|
compiler.plugin("compilation", compilation => {
|
47
82
|
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
83
|
+
|
48
84
|
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
49
85
|
const moduleToSourceNameMapping = new Map();
|
50
86
|
const tasks = [];
|
87
|
+
|
51
88
|
chunks.forEach(function(chunk) {
|
52
|
-
chunk.files.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
72
|
-
if(sourceMap) {
|
73
|
-
return {
|
74
|
-
chunk,
|
75
|
-
file,
|
76
|
-
asset,
|
77
|
-
source,
|
78
|
-
sourceMap
|
79
|
-
};
|
80
|
-
}
|
81
|
-
}).filter(Boolean).map(task => {
|
82
|
-
const modules = task.sourceMap.sources.map(source => {
|
83
|
-
const module = compilation.findModule(source);
|
84
|
-
return module || source;
|
85
|
-
});
|
86
|
-
for(const module of modules) {
|
87
|
-
if(!moduleToSourceNameMapping.get(module)) {
|
88
|
-
moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
|
89
|
+
chunk.files.forEach(file => {
|
90
|
+
if(matchObject(file)) {
|
91
|
+
const task = getTaskForFile(file, chunk, options, compilation);
|
92
|
+
|
93
|
+
if(task) {
|
94
|
+
const modules = task.sourceMap.sources.map(source => {
|
95
|
+
const module = compilation.findModule(source);
|
96
|
+
return module || source;
|
97
|
+
});
|
98
|
+
|
99
|
+
for(const module of modules) {
|
100
|
+
if(!moduleToSourceNameMapping.get(module)) {
|
101
|
+
moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
task.modules = modules;
|
106
|
+
|
107
|
+
tasks.push(task);
|
89
108
|
}
|
90
109
|
}
|
91
|
-
task.modules = modules;
|
92
|
-
return task;
|
93
|
-
}).forEach(task => {
|
94
|
-
tasks.push(task);
|
95
110
|
});
|
96
111
|
});
|
112
|
+
|
97
113
|
const usedNamesSet = new Set(moduleToSourceNameMapping.values());
|
98
114
|
const conflictDetectionSet = new Set();
|
99
115
|
|
package/lib/Stats.js
CHANGED
@@ -7,8 +7,13 @@
|
|
7
7
|
const RequestShortener = require("./RequestShortener");
|
8
8
|
const SizeFormatHelpers = require("./SizeFormatHelpers");
|
9
9
|
const formatLocation = require("./formatLocation");
|
10
|
+
const identifierUtils = require("./util/identifier");
|
10
11
|
|
11
|
-
const
|
12
|
+
const optionsOrFallback = function() {
|
13
|
+
let optionValues = [];
|
14
|
+
optionValues.push.apply(optionValues, arguments);
|
15
|
+
return optionValues.find(optionValue => typeof optionValue !== "undefined");
|
16
|
+
};
|
12
17
|
|
13
18
|
class Stats {
|
14
19
|
constructor(compilation) {
|
@@ -79,8 +84,20 @@ class Stats {
|
|
79
84
|
typeof v !== "undefined" ? v :
|
80
85
|
typeof options.all !== "undefined" ? options.all : def;
|
81
86
|
|
87
|
+
const testAgainstGivenOption = (item) => {
|
88
|
+
if(typeof item === "string") {
|
89
|
+
const regExp = new RegExp(`[\\\\/]${item.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")}([\\\\/]|$|!|\\?)`); // eslint-disable-line no-useless-escape
|
90
|
+
return ident => regExp.test(ident);
|
91
|
+
}
|
92
|
+
if(item && typeof item === "object" && typeof item.test === "function")
|
93
|
+
return ident => item.test(ident);
|
94
|
+
if(typeof item === "function")
|
95
|
+
return item;
|
96
|
+
};
|
97
|
+
|
82
98
|
const compilation = this.compilation;
|
83
|
-
const
|
99
|
+
const context = optionsOrFallback(options.context, process.cwd());
|
100
|
+
const requestShortener = new RequestShortener(context);
|
84
101
|
const showPerformance = optionOrLocalFallback(options.performance, true);
|
85
102
|
const showHash = optionOrLocalFallback(options.hash, true);
|
86
103
|
const showVersion = optionOrLocalFallback(options.version, true);
|
@@ -104,22 +121,14 @@ class Stats {
|
|
104
121
|
const showErrors = optionOrLocalFallback(options.errors, true);
|
105
122
|
const showErrorDetails = optionOrLocalFallback(options.errorDetails, !forToString);
|
106
123
|
const showWarnings = optionOrLocalFallback(options.warnings, true);
|
107
|
-
const warningsFilter =
|
124
|
+
const warningsFilter = optionsOrFallback(options.warningsFilter, null);
|
108
125
|
const showPublicPath = optionOrLocalFallback(options.publicPath, !forToString);
|
109
|
-
const excludeModules = [].concat(
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
return ident => item.test(ident);
|
116
|
-
if(typeof item === "function")
|
117
|
-
return item;
|
118
|
-
});
|
119
|
-
const maxModules = optionOrFallback(options.maxModules, forToString ? 15 : Infinity);
|
120
|
-
const sortModules = optionOrFallback(options.modulesSort, "id");
|
121
|
-
const sortChunks = optionOrFallback(options.chunksSort, "id");
|
122
|
-
const sortAssets = optionOrFallback(options.assetsSort, "");
|
126
|
+
const excludeModules = [].concat(optionsOrFallback(options.excludeModules, options.exclude, [])).map(testAgainstGivenOption);
|
127
|
+
const excludeAssets = [].concat(optionsOrFallback(options.excludeAssets, [])).map(testAgainstGivenOption);
|
128
|
+
const maxModules = optionsOrFallback(options.maxModules, forToString ? 15 : Infinity);
|
129
|
+
const sortModules = optionsOrFallback(options.modulesSort, "id");
|
130
|
+
const sortChunks = optionsOrFallback(options.chunksSort, "id");
|
131
|
+
const sortAssets = optionsOrFallback(options.assetsSort, "");
|
123
132
|
|
124
133
|
if(!showCachedModules) {
|
125
134
|
excludeModules.push((ident, module) => !module.built);
|
@@ -138,6 +147,18 @@ class Stats {
|
|
138
147
|
};
|
139
148
|
};
|
140
149
|
|
150
|
+
const createAssetFilter = () => {
|
151
|
+
return asset => {
|
152
|
+
if(excludeAssets.length > 0) {
|
153
|
+
const ident = asset.name;
|
154
|
+
const excluded = excludeAssets.some(fn => fn(ident, asset));
|
155
|
+
if(excluded)
|
156
|
+
return false;
|
157
|
+
}
|
158
|
+
return showCachedAssets || asset.emitted;
|
159
|
+
};
|
160
|
+
};
|
161
|
+
|
141
162
|
const sortByFieldAndOrder = (fieldKey, a, b) => {
|
142
163
|
if(a[fieldKey] === null && b[fieldKey] === null) return 0;
|
143
164
|
if(a[fieldKey] === null) return 1;
|
@@ -229,8 +250,9 @@ class Stats {
|
|
229
250
|
}
|
230
251
|
if(showAssets) {
|
231
252
|
const assetsByFile = {};
|
253
|
+
const compilationAssets = Object.keys(compilation.assets);
|
232
254
|
obj.assetsByChunkName = {};
|
233
|
-
obj.assets =
|
255
|
+
obj.assets = compilationAssets.map(asset => {
|
234
256
|
const obj = {
|
235
257
|
name: asset,
|
236
258
|
size: compilation.assets[asset].size(),
|
@@ -245,7 +267,8 @@ class Stats {
|
|
245
267
|
|
246
268
|
assetsByFile[asset] = obj;
|
247
269
|
return obj;
|
248
|
-
}).filter(
|
270
|
+
}).filter(createAssetFilter());
|
271
|
+
obj.filteredAssets = compilationAssets.length - obj.assets.length;
|
249
272
|
|
250
273
|
compilation.chunks.forEach(chunk => {
|
251
274
|
chunk.files.forEach(asset => {
|
@@ -391,7 +414,8 @@ class Stats {
|
|
391
414
|
const obj = new Stats(child).toJson(childOptions, forToString);
|
392
415
|
delete obj.hash;
|
393
416
|
delete obj.version;
|
394
|
-
|
417
|
+
if(child.name)
|
418
|
+
obj.name = identifierUtils.makePathsRelative(context, child.name, compilation.cache);
|
395
419
|
return obj;
|
396
420
|
});
|
397
421
|
}
|
@@ -406,7 +430,7 @@ class Stats {
|
|
406
430
|
options = {};
|
407
431
|
}
|
408
432
|
|
409
|
-
const useColors =
|
433
|
+
const useColors = optionsOrFallback(options.colors, false);
|
410
434
|
|
411
435
|
const obj = this.toJson(options, true);
|
412
436
|
|
@@ -573,6 +597,16 @@ class Stats {
|
|
573
597
|
});
|
574
598
|
table(t, "rrrlll");
|
575
599
|
}
|
600
|
+
if(obj.filteredAssets > 0) {
|
601
|
+
colors.normal(" ");
|
602
|
+
if(obj.assets.length > 0)
|
603
|
+
colors.normal("+ ");
|
604
|
+
colors.normal(obj.filteredAssets);
|
605
|
+
if(obj.assets.length > 0)
|
606
|
+
colors.normal(" hidden");
|
607
|
+
colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
|
608
|
+
newline();
|
609
|
+
}
|
576
610
|
if(obj.entrypoints) {
|
577
611
|
Object.keys(obj.entrypoints).forEach(name => {
|
578
612
|
const ep = obj.entrypoints[name];
|
@@ -650,7 +684,7 @@ class Stats {
|
|
650
684
|
if(module.usedExports !== undefined) {
|
651
685
|
if(module.usedExports !== true) {
|
652
686
|
colors.normal(prefix);
|
653
|
-
if(module.usedExports === false)
|
687
|
+
if(module.usedExports === false || module.usedExports.length === 0)
|
654
688
|
colors.cyan("[no exports used]");
|
655
689
|
else
|
656
690
|
colors.cyan(`[only some exports used: ${module.usedExports.join(", ")}]`);
|
@@ -687,9 +721,9 @@ class Stats {
|
|
687
721
|
const path = [];
|
688
722
|
let current = module;
|
689
723
|
while(current.issuer) {
|
690
|
-
path.
|
724
|
+
path.push(current = current.issuer);
|
691
725
|
}
|
692
|
-
path.forEach(module => {
|
726
|
+
path.reverse().forEach(module => {
|
693
727
|
colors.normal("[");
|
694
728
|
colors.normal(module.id);
|
695
729
|
colors.normal("] ");
|
package/lib/Template.js
CHANGED
@@ -28,7 +28,7 @@ module.exports = class Template extends Tapable {
|
|
28
28
|
|
29
29
|
static toPath(str) {
|
30
30
|
if(typeof str !== "string") return "";
|
31
|
-
return str.replace(/[^a-zA-Z0-9_!§$()
|
31
|
+
return str.replace(/[^a-zA-Z0-9_!§$()=\-^°]+/g, "-").replace(/^-|-$/, "");
|
32
32
|
}
|
33
33
|
|
34
34
|
// map number to a single character a-z, A-Z or <_ + number> if number is too big
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const NullDependency = require("./NullDependency");
|
7
|
+
|
8
|
+
class DelegatedExportsDependency extends NullDependency {
|
9
|
+
constructor(originModule, exports) {
|
10
|
+
super();
|
11
|
+
this.originModule = originModule;
|
12
|
+
this.exports = exports;
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "delegated exports";
|
17
|
+
}
|
18
|
+
|
19
|
+
getReference() {
|
20
|
+
return {
|
21
|
+
module: this.originModule,
|
22
|
+
importedNames: true
|
23
|
+
};
|
24
|
+
}
|
25
|
+
|
26
|
+
getExports() {
|
27
|
+
return {
|
28
|
+
exports: this.exports
|
29
|
+
};
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
module.exports = DelegatedExportsDependency;
|
@@ -21,7 +21,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
|
|
21
21
|
const usedExports = dep.originModule.usedExports;
|
22
22
|
if(usedExports && !Array.isArray(usedExports)) {
|
23
23
|
const exportName = dep.originModule.exportsArgument || "exports";
|
24
|
-
const content = `Object.defineProperty(${exportName},
|
24
|
+
const content = `Object.defineProperty(${exportName}, "__esModule", { value: true });\n`;
|
25
25
|
source.insert(-10, content);
|
26
26
|
}
|
27
27
|
}
|
@@ -5,6 +5,8 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
|
8
|
+
const ImportWeakDependency = require("./ImportWeakDependency");
|
9
|
+
const ImportWeakContextDependency = require("./ImportWeakContextDependency");
|
8
10
|
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
|
9
11
|
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
|
10
12
|
const ImportDependenciesBlock = require("./ImportDependenciesBlock");
|
@@ -46,26 +48,31 @@ class ImportParserPlugin {
|
|
46
48
|
}
|
47
49
|
|
48
50
|
if(param.isString()) {
|
49
|
-
if(mode !== "lazy" && mode !== "eager") {
|
50
|
-
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy' or '
|
51
|
+
if(mode !== "lazy" && mode !== "eager" && mode !== "weak") {
|
52
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}.`));
|
51
53
|
}
|
52
54
|
|
53
55
|
if(mode === "eager") {
|
54
56
|
const dep = new ImportEagerDependency(param.string, expr.range);
|
55
57
|
parser.state.current.addDependency(dep);
|
58
|
+
} else if(mode === "weak") {
|
59
|
+
const dep = new ImportWeakDependency(param.string, expr.range);
|
60
|
+
parser.state.current.addDependency(dep);
|
56
61
|
} else {
|
57
62
|
const depBlock = new ImportDependenciesBlock(param.string, expr.range, chunkName, parser.state.module, expr.loc);
|
58
63
|
parser.state.current.addBlock(depBlock);
|
59
64
|
}
|
60
65
|
return true;
|
61
66
|
} else {
|
62
|
-
if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager") {
|
63
|
-
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once' or '
|
67
|
+
if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager" && mode !== "weak") {
|
68
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`));
|
64
69
|
}
|
65
70
|
|
66
71
|
let Dep = ImportLazyContextDependency;
|
67
72
|
if(mode === "eager") {
|
68
73
|
Dep = ImportEagerContextDependency;
|
74
|
+
} else if(mode === "weak") {
|
75
|
+
Dep = ImportWeakContextDependency;
|
69
76
|
} else if(mode === "lazy-once") {
|
70
77
|
Dep = ImportLazyOnceContextDependency;
|
71
78
|
}
|
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
const ImportDependency = require("./ImportDependency");
|
8
8
|
const ImportEagerDependency = require("./ImportEagerDependency");
|
9
|
+
const ImportWeakDependency = require("./ImportWeakDependency");
|
9
10
|
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
|
11
|
+
const ImportWeakContextDependency = require("./ImportWeakContextDependency");
|
10
12
|
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
|
11
13
|
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
|
12
14
|
const ImportParserPlugin = require("./ImportParserPlugin");
|
@@ -28,9 +30,15 @@ class ImportPlugin {
|
|
28
30
|
compilation.dependencyFactories.set(ImportEagerDependency, normalModuleFactory);
|
29
31
|
compilation.dependencyTemplates.set(ImportEagerDependency, new ImportEagerDependency.Template());
|
30
32
|
|
33
|
+
compilation.dependencyFactories.set(ImportWeakDependency, normalModuleFactory);
|
34
|
+
compilation.dependencyTemplates.set(ImportWeakDependency, new ImportWeakDependency.Template());
|
35
|
+
|
31
36
|
compilation.dependencyFactories.set(ImportEagerContextDependency, contextModuleFactory);
|
32
37
|
compilation.dependencyTemplates.set(ImportEagerContextDependency, new ImportEagerContextDependency.Template());
|
33
38
|
|
39
|
+
compilation.dependencyFactories.set(ImportWeakContextDependency, contextModuleFactory);
|
40
|
+
compilation.dependencyTemplates.set(ImportWeakContextDependency, new ImportWeakContextDependency.Template());
|
41
|
+
|
34
42
|
compilation.dependencyFactories.set(ImportLazyOnceContextDependency, contextModuleFactory);
|
35
43
|
compilation.dependencyTemplates.set(ImportLazyOnceContextDependency, new ImportLazyOnceContextDependency.Template());
|
36
44
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportWeakContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "async-weak";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context weak";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportWeakContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportWeakContextDependency;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ModuleDependency = require("./ModuleDependency");
|
7
|
+
const webpackMissingPromiseModule = require("./WebpackMissingModule").promise;
|
8
|
+
|
9
|
+
class ImportWeakDependency extends ModuleDependency {
|
10
|
+
constructor(request, range) {
|
11
|
+
super(request);
|
12
|
+
this.range = range;
|
13
|
+
this.weak = true;
|
14
|
+
}
|
15
|
+
|
16
|
+
get type() {
|
17
|
+
return "import() weak";
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
ImportWeakDependency.Template = class ImportDependencyTemplate {
|
22
|
+
apply(dep, source, outputOptions, requestShortener) {
|
23
|
+
const comment = this.getOptionalComment(outputOptions.pathinfo, requestShortener.shorten(dep.request));
|
24
|
+
|
25
|
+
const content = this.getContent(dep, comment);
|
26
|
+
source.replace(dep.range[0], dep.range[1] - 1, content);
|
27
|
+
}
|
28
|
+
|
29
|
+
getOptionalComment(pathinfo, shortenedRequest) {
|
30
|
+
if(!pathinfo) {
|
31
|
+
return "";
|
32
|
+
}
|
33
|
+
|
34
|
+
return `/*! ${shortenedRequest} */ `;
|
35
|
+
}
|
36
|
+
|
37
|
+
getContent(dep, comment) {
|
38
|
+
if(dep.module) {
|
39
|
+
const stringifiedId = JSON.stringify(dep.module.id);
|
40
|
+
return `Promise.resolve(${comment}${stringifiedId}).then(function(id) { if(!__webpack_require__.m[id]) throw new Error("Module '" + id + "' is not available (weak dependency)"); return __webpack_require__(id); })`;
|
41
|
+
}
|
42
|
+
|
43
|
+
return webpackMissingPromiseModule(dep.request);
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
module.exports = ImportWeakDependency;
|
@@ -7,9 +7,13 @@ const ContextDependency = require("./ContextDependency");
|
|
7
7
|
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
8
8
|
|
9
9
|
class RequireContextDependency extends ContextDependency {
|
10
|
-
constructor(request, recursive, regExp, range) {
|
10
|
+
constructor(request, recursive, regExp, asyncMode, range) {
|
11
11
|
super(request, recursive, regExp);
|
12
12
|
this.range = range;
|
13
|
+
|
14
|
+
if(asyncMode) {
|
15
|
+
this.async = asyncMode;
|
16
|
+
}
|
13
17
|
}
|
14
18
|
|
15
19
|
get type() {
|
@@ -11,7 +11,15 @@ module.exports = class RequireContextDependencyParserPlugin {
|
|
11
11
|
parser.plugin("call require.context", expr => {
|
12
12
|
let regExp = /^\.\/.*$/;
|
13
13
|
let recursive = true;
|
14
|
+
let asyncMode;
|
14
15
|
switch(expr.arguments.length) {
|
16
|
+
case 4:
|
17
|
+
{
|
18
|
+
const asyncModeExpr = parser.evaluateExpression(expr.arguments[3]);
|
19
|
+
if(!asyncModeExpr.isString()) return;
|
20
|
+
asyncMode = asyncModeExpr.string;
|
21
|
+
}
|
22
|
+
// falls through
|
15
23
|
case 3:
|
16
24
|
{
|
17
25
|
const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
|
@@ -30,7 +38,7 @@ module.exports = class RequireContextDependencyParserPlugin {
|
|
30
38
|
{
|
31
39
|
const requestExpr = parser.evaluateExpression(expr.arguments[0]);
|
32
40
|
if(!requestExpr.isString()) return;
|
33
|
-
const dep = new RequireContextDependency(requestExpr.string, recursive, regExp, expr.range);
|
41
|
+
const dep = new RequireContextDependency(requestExpr.string, recursive, regExp, asyncMode, expr.range);
|
34
42
|
dep.loc = expr.loc;
|
35
43
|
dep.optional = parser.scope.inTry;
|
36
44
|
parser.state.current.addDependency(dep);
|
@@ -31,86 +31,80 @@ class AggressiveMergingPlugin {
|
|
31
31
|
for(let i = 0; i < idx; i++) {
|
32
32
|
const b = chunks[i];
|
33
33
|
if(b.isInitial()) continue;
|
34
|
-
combinations.push(
|
34
|
+
combinations.push({
|
35
|
+
a,
|
36
|
+
b,
|
37
|
+
improvement: undefined
|
38
|
+
});
|
35
39
|
}
|
36
40
|
});
|
37
41
|
|
38
42
|
combinations.forEach((pair) => {
|
39
|
-
const a = pair
|
43
|
+
const a = pair.b.size({
|
40
44
|
chunkOverhead: 0
|
41
45
|
});
|
42
|
-
const b = pair
|
46
|
+
const b = pair.a.size({
|
43
47
|
chunkOverhead: 0
|
44
48
|
});
|
45
|
-
const ab = pair
|
49
|
+
const ab = pair.b.integratedSize(pair.a, {
|
46
50
|
chunkOverhead: 0
|
47
51
|
});
|
48
|
-
pair.push({
|
49
|
-
a: a,
|
50
|
-
b: b,
|
51
|
-
ab: ab
|
52
|
-
});
|
53
52
|
let newSize;
|
54
53
|
if(ab === false) {
|
55
|
-
pair.
|
54
|
+
pair.improvement = false;
|
55
|
+
return;
|
56
56
|
} else if(options.moveToParents) {
|
57
57
|
const aOnly = ab - b;
|
58
58
|
const bOnly = ab - a;
|
59
59
|
const common = a + b - ab;
|
60
|
-
newSize = common + getParentsWeight(pair
|
61
|
-
pair.push({
|
62
|
-
aOnly: aOnly,
|
63
|
-
bOnly: bOnly,
|
64
|
-
common: common,
|
65
|
-
newSize: newSize
|
66
|
-
});
|
60
|
+
newSize = common + getParentsWeight(pair.b) * aOnly + getParentsWeight(pair.a) * bOnly;
|
67
61
|
} else {
|
68
62
|
newSize = ab;
|
69
63
|
}
|
70
64
|
|
71
|
-
pair.
|
65
|
+
pair.improvement = (a + b) / newSize;
|
72
66
|
});
|
73
67
|
combinations = combinations.filter((pair) => {
|
74
|
-
return pair
|
68
|
+
return pair.improvement !== false;
|
75
69
|
});
|
76
70
|
combinations.sort((a, b) => {
|
77
|
-
return b
|
71
|
+
return b.improvement - a.improvement;
|
78
72
|
});
|
79
73
|
|
80
74
|
const pair = combinations[0];
|
81
75
|
|
82
76
|
if(!pair) return;
|
83
|
-
if(pair
|
77
|
+
if(pair.improvement < minSizeReduce) return;
|
84
78
|
|
85
79
|
if(options.moveToParents) {
|
86
|
-
const commonModules = pair
|
87
|
-
return pair
|
80
|
+
const commonModules = pair.b.modules.filter((m) => {
|
81
|
+
return pair.a.modules.indexOf(m) >= 0;
|
88
82
|
});
|
89
|
-
const aOnlyModules = pair
|
83
|
+
const aOnlyModules = pair.b.modules.filter((m) => {
|
90
84
|
return commonModules.indexOf(m) < 0;
|
91
85
|
});
|
92
|
-
const bOnlyModules = pair
|
86
|
+
const bOnlyModules = pair.a.modules.filter((m) => {
|
93
87
|
return commonModules.indexOf(m) < 0;
|
94
88
|
});
|
95
89
|
aOnlyModules.forEach((m) => {
|
96
|
-
pair
|
97
|
-
m.removeChunk(pair
|
98
|
-
pair
|
90
|
+
pair.b.removeModule(m);
|
91
|
+
m.removeChunk(pair.b);
|
92
|
+
pair.b.parents.forEach((c) => {
|
99
93
|
c.addModule(m);
|
100
94
|
m.addChunk(c);
|
101
95
|
});
|
102
96
|
});
|
103
97
|
bOnlyModules.forEach((m) => {
|
104
|
-
pair
|
105
|
-
m.removeChunk(pair
|
106
|
-
pair
|
98
|
+
pair.a.removeModule(m);
|
99
|
+
m.removeChunk(pair.a);
|
100
|
+
pair.a.parents.forEach((c) => {
|
107
101
|
c.addModule(m);
|
108
102
|
m.addChunk(c);
|
109
103
|
});
|
110
104
|
});
|
111
105
|
}
|
112
|
-
if(pair
|
113
|
-
chunks.splice(chunks.indexOf(pair
|
106
|
+
if(pair.b.integrate(pair.a, "aggressive-merge")) {
|
107
|
+
chunks.splice(chunks.indexOf(pair.a), 1);
|
114
108
|
return true;
|
115
109
|
}
|
116
110
|
});
|