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.
Files changed (40) hide show
  1. package/README.md +34 -11
  2. package/bin/config-optimist.js +1 -0
  3. package/bin/config-yargs.js +12 -4
  4. package/bin/convert-argv.js +28 -8
  5. package/bin/webpack.js +198 -182
  6. package/lib/ContextModule.js +87 -13
  7. package/lib/DelegatedModule.js +10 -4
  8. package/lib/DelegatedModuleFactoryPlugin.js +5 -4
  9. package/lib/DelegatedPlugin.js +3 -0
  10. package/lib/DllReferencePlugin.js +3 -0
  11. package/lib/ExternalModule.js +6 -1
  12. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  13. package/lib/HotModuleReplacement.runtime.js +13 -5
  14. package/lib/MultiCompiler.js +2 -2
  15. package/lib/NormalModule.js +32 -9
  16. package/lib/NormalModuleFactory.js +133 -145
  17. package/lib/Parser.js +52 -58
  18. package/lib/RecordIdsPlugin.js +3 -3
  19. package/lib/SourceMapDevToolPlugin.js +57 -41
  20. package/lib/Stats.js +58 -24
  21. package/lib/Template.js +1 -1
  22. package/lib/dependencies/DelegatedExportsDependency.js +33 -0
  23. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
  24. package/lib/dependencies/ImportParserPlugin.js +11 -4
  25. package/lib/dependencies/ImportPlugin.js +8 -0
  26. package/lib/dependencies/ImportWeakContextDependency.js +22 -0
  27. package/lib/dependencies/ImportWeakDependency.js +47 -0
  28. package/lib/dependencies/RequireContextDependency.js +5 -1
  29. package/lib/dependencies/RequireContextDependencyParserPlugin.js +9 -1
  30. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +1 -1
  31. package/lib/optimize/AggressiveMergingPlugin.js +27 -33
  32. package/lib/optimize/AggressiveSplittingPlugin.js +46 -33
  33. package/lib/optimize/ChunkModuleIdRangePlugin.js +1 -3
  34. package/lib/optimize/CommonsChunkPlugin.js +11 -4
  35. package/lib/optimize/ConcatenatedModule.js +403 -229
  36. package/lib/optimize/ModuleConcatenationPlugin.js +30 -35
  37. package/lib/util/identifier.js +23 -1
  38. package/lib/webpack.js +52 -55
  39. package/package.json +10 -10
  40. 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
- for(let i = 0; i < chunks.length; i++) {
52
- const chunk = chunks[i];
58
+ const selectedModules = splitData.modules.map(name => nameToModuleMap.get(name));
53
59
 
54
- if(chunk.getNumberOfModules() < splitData.modules.length)
55
- continue;
60
+ // Does the modules exist at all?
61
+ if(selectedModules.every(Boolean)) {
56
62
 
57
- const nameToModuleMap = new Map();
58
- chunk.forEachModule(m => {
59
- const name = identifierUtils.makePathsRelative(compiler.context, m.identifier());
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
- const selectedModules = splitData.modules.map(name => nameToModuleMap.get(name));
64
- if(selectedModules.every(Boolean)) {
65
- if(chunk.getNumberOfModules() > splitData.modules.length) {
66
- const newChunk = compilation.addChunk();
67
- selectedModules.forEach(moveModuleBetween(chunk, newChunk));
68
- chunk.split(newChunk);
69
- chunk.name = null;
70
- newChunk._fromAggressiveSplitting = true;
71
- if(j < savedSplits.length)
72
- newChunk._fromAggressiveSplittingIndex = j;
73
- if(splitData.id !== null && splitData.id !== undefined) {
74
- newChunk.id = splitData.id;
75
- }
76
- newChunk.origins = chunk.origins.map(copyWithReason);
77
- chunk.origins = chunk.origins.map(copyWithReason);
78
- return true;
79
- } else {
80
- if(j < savedSplits.length)
81
- chunk._fromAggressiveSplittingIndex = j;
82
- chunk.name = null;
83
- if(splitData.id !== null && splitData.id !== undefined) {
84
- chunk.id = splitData.id;
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.filter((chunk) => {
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 \"async\" option.
64
- You can however specify the name of the async chunk by passing the desired string as the \"async\" option.`);
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.filter(chunk => !chunk.isInitial());
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
- return asyncOption || chunk.parents.length === 1;
237
+ if(!asyncOption)
238
+ return chunk.parents.length === 1;
239
+
240
+ return true;
234
241
  });
235
242
  }
236
243