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
@@ -39,6 +39,13 @@ class AggressiveSplittingPlugin {
|
|
39
39
|
apply(compiler) {
|
40
40
|
compiler.plugin("this-compilation", (compilation) => {
|
41
41
|
compilation.plugin("optimize-chunks-advanced", (chunks) => {
|
42
|
+
// Precompute stuff
|
43
|
+
const nameToModuleMap = new Map();
|
44
|
+
compilation.modules.forEach(m => {
|
45
|
+
const name = identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache);
|
46
|
+
nameToModuleMap.set(name, m);
|
47
|
+
});
|
48
|
+
|
42
49
|
const savedSplits = compilation.records && compilation.records.aggressiveSplits || [];
|
43
50
|
const usedSplits = compilation._aggressiveSplittingSplits ?
|
44
51
|
savedSplits.concat(compilation._aggressiveSplittingSplits) : savedSplits;
|
@@ -48,45 +55,51 @@ class AggressiveSplittingPlugin {
|
|
48
55
|
// 1. try to restore to recorded splitting
|
49
56
|
for(let j = 0; j < usedSplits.length; j++) {
|
50
57
|
const splitData = usedSplits[j];
|
51
|
-
|
52
|
-
const chunk = chunks[i];
|
58
|
+
const selectedModules = splitData.modules.map(name => nameToModuleMap.get(name));
|
53
59
|
|
54
|
-
|
55
|
-
|
60
|
+
// Does the modules exist at all?
|
61
|
+
if(selectedModules.every(Boolean)) {
|
56
62
|
|
57
|
-
|
58
|
-
|
59
|
-
const
|
60
|
-
nameToModuleMap.set(name, m);
|
61
|
-
});
|
63
|
+
// Find all chunks containing all modules in the split
|
64
|
+
for(let i = 0; i < chunks.length; i++) {
|
65
|
+
const chunk = chunks[i];
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
chunk.
|
67
|
+
// Cheap check if chunk is suitable at all
|
68
|
+
if(chunk.getNumberOfModules() < splitData.modules.length)
|
69
|
+
continue;
|
70
|
+
|
71
|
+
// Check if all modules are in the chunk
|
72
|
+
if(selectedModules.every(m => chunk.containsModule(m))) {
|
73
|
+
|
74
|
+
// Is chunk identical to the split or do we need to split it?
|
75
|
+
if(chunk.getNumberOfModules() > splitData.modules.length) {
|
76
|
+
// split the chunk into two parts
|
77
|
+
const newChunk = compilation.addChunk();
|
78
|
+
selectedModules.forEach(moveModuleBetween(chunk, newChunk));
|
79
|
+
chunk.split(newChunk);
|
80
|
+
chunk.name = null;
|
81
|
+
newChunk._fromAggressiveSplitting = true;
|
82
|
+
if(j < savedSplits.length)
|
83
|
+
newChunk._fromAggressiveSplittingIndex = j;
|
84
|
+
if(splitData.id !== null && splitData.id !== undefined) {
|
85
|
+
newChunk.id = splitData.id;
|
86
|
+
}
|
87
|
+
newChunk.origins = chunk.origins.map(copyWithReason);
|
88
|
+
chunk.origins = chunk.origins.map(copyWithReason);
|
89
|
+
return true;
|
90
|
+
} else { // chunk is identical to the split
|
91
|
+
if(j < savedSplits.length)
|
92
|
+
chunk._fromAggressiveSplittingIndex = j;
|
93
|
+
chunk.name = null;
|
94
|
+
if(splitData.id !== null && splitData.id !== undefined) {
|
95
|
+
chunk.id = splitData.id;
|
96
|
+
}
|
85
97
|
}
|
86
98
|
}
|
87
99
|
}
|
88
100
|
}
|
89
101
|
}
|
102
|
+
|
90
103
|
// 2. for any other chunk which isn't splitted yet, split it
|
91
104
|
for(let i = 0; i < chunks.length; i++) {
|
92
105
|
const chunk = chunks[i];
|
@@ -127,7 +140,7 @@ class AggressiveSplittingPlugin {
|
|
127
140
|
newChunk.origins = chunk.origins.map(copyWithReason);
|
128
141
|
chunk.origins = chunk.origins.map(copyWithReason);
|
129
142
|
compilation._aggressiveSplittingSplits = (compilation._aggressiveSplittingSplits || []).concat({
|
130
|
-
modules: newChunk.mapModules(m => identifierUtils.makePathsRelative(compiler.context, m.identifier()))
|
143
|
+
modules: newChunk.mapModules(m => identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache))
|
131
144
|
});
|
132
145
|
return true;
|
133
146
|
} else {
|
@@ -144,7 +157,7 @@ class AggressiveSplittingPlugin {
|
|
144
157
|
if(chunk.hasEntryModule()) return;
|
145
158
|
const size = chunk.size(this.options);
|
146
159
|
const incorrectSize = size < minSize;
|
147
|
-
const modules = chunk.mapModules(m => identifierUtils.makePathsRelative(compiler.context, m.identifier()));
|
160
|
+
const modules = chunk.mapModules(m => identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache));
|
148
161
|
if(typeof chunk._fromAggressiveSplittingIndex === "undefined") {
|
149
162
|
if(incorrectSize) return;
|
150
163
|
chunk.recorded = true;
|
@@ -11,9 +11,7 @@ class ChunkModuleIdRangePlugin {
|
|
11
11
|
const options = this.options;
|
12
12
|
compiler.plugin("compilation", (compilation) => {
|
13
13
|
compilation.plugin("module-ids", (modules) => {
|
14
|
-
const chunk = this.chunks.
|
15
|
-
return chunk.name === options.name;
|
16
|
-
})[0];
|
14
|
+
const chunk = this.chunks.find((chunk) => chunk.name === options.name);
|
17
15
|
if(!chunk) throw new Error("ChunkModuleIdRangePlugin: Chunk with name '" + options.name + "' was not found");
|
18
16
|
let currentId = options.start;
|
19
17
|
let chunkModules;
|
@@ -60,8 +60,8 @@ The available options are:
|
|
60
60
|
* that webpack will take care of loading this file.
|
61
61
|
*/
|
62
62
|
if(options.async && options.filename) {
|
63
|
-
throw new Error(`You can not specify a filename if you use the
|
64
|
-
You can however specify the name of the async chunk by passing the desired string as the
|
63
|
+
throw new Error(`You can not specify a filename if you use the "async" option.
|
64
|
+
You can however specify the name of the async chunk by passing the desired string as the "async" option.`);
|
65
65
|
}
|
66
66
|
|
67
67
|
/**
|
@@ -201,7 +201,7 @@ You can however specify the name of the async chunk by passing the desired strin
|
|
201
201
|
|
202
202
|
// we dont have named chunks specified, so we just take all of them
|
203
203
|
if(asyncOrNoSelectedChunk) {
|
204
|
-
return allChunks
|
204
|
+
return allChunks;
|
205
205
|
}
|
206
206
|
|
207
207
|
/**
|
@@ -229,8 +229,15 @@ Take a look at the "name"/"names" or async/children option.`);
|
|
229
229
|
}
|
230
230
|
|
231
231
|
return targetChunk.chunks.filter((chunk) => {
|
232
|
+
// we only are interested in on-demand chunks
|
233
|
+
if(chunk.isInitial())
|
234
|
+
return false;
|
235
|
+
|
232
236
|
// we can only move modules from this chunk if the "commonChunk" is the only parent
|
233
|
-
|
237
|
+
if(!asyncOption)
|
238
|
+
return chunk.parents.length === 1;
|
239
|
+
|
240
|
+
return true;
|
234
241
|
});
|
235
242
|
}
|
236
243
|
|