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
@@ -7,6 +7,11 @@
7
7
  const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
8
8
  const ConcatenatedModule = require("./ConcatenatedModule");
9
9
  const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
10
+ const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
11
+
12
+ function formatBailoutReason(msg) {
13
+ return "ModuleConcatenation bailout: " + msg;
14
+ }
10
15
 
11
16
  class ModuleConcatenationPlugin {
12
17
  constructor(options) {
@@ -23,9 +28,9 @@ class ModuleConcatenationPlugin {
23
28
  });
24
29
  const bailoutReasonMap = new Map();
25
30
 
26
- function setBailoutReason(module, prefix, reason) {
31
+ function setBailoutReason(module, reason) {
27
32
  bailoutReasonMap.set(module, reason);
28
- module.optimizationBailout.push(typeof reason === "function" ? (rs) => `${prefix}: ${reason(rs)}` : `${prefix}: ${reason}`);
33
+ module.optimizationBailout.push(typeof reason === "function" ? (rs) => formatBailoutReason(reason(rs)) : formatBailoutReason(reason));
29
34
  }
30
35
 
31
36
  function getBailoutReason(module, requestShortener) {
@@ -39,33 +44,34 @@ class ModuleConcatenationPlugin {
39
44
  const possibleInners = new Set();
40
45
  for(const module of modules) {
41
46
  // Only harmony modules are valid for optimization
42
- if(!module.meta || !module.meta.harmonyModule) {
47
+ if(!module.meta || !module.meta.harmonyModule || !module.dependencies.some(d => d instanceof HarmonyCompatibilityDependency)) {
48
+ setBailoutReason(module, "Module is not an ECMAScript module");
43
49
  continue;
44
50
  }
45
51
 
46
52
  // Because of variable renaming we can't use modules with eval
47
53
  if(module.meta && module.meta.hasEval) {
48
- setBailoutReason(module, "ModuleConcatenation", "eval is used in the module");
49
- continue;
50
- }
51
-
52
- relevantModules.push(module);
53
-
54
- // Module must not be the entry points
55
- if(module.getChunks().some(chunk => chunk.entryModule === module)) {
56
- setBailoutReason(module, "ModuleConcatenation (inner)", "module is an entrypoint");
54
+ setBailoutReason(module, "Module uses eval()");
57
55
  continue;
58
56
  }
59
57
 
60
58
  // Exports must be known (and not dynamic)
61
59
  if(!Array.isArray(module.providedExports)) {
62
- setBailoutReason(module, "ModuleConcatenation (inner)", "exports are not known");
60
+ setBailoutReason(module, "Module exports are unknown");
63
61
  continue;
64
62
  }
65
63
 
66
64
  // Using dependency variables is not possible as this wraps the code in a function
67
65
  if(module.variables.length > 0) {
68
- setBailoutReason(module, "ModuleConcatenation (inner)", "dependency variables are used (i. e. ProvidePlugin)");
66
+ setBailoutReason(module, `Module uses injected variables (${module.variables.map(v => v.name).join(", ")})`);
67
+ continue;
68
+ }
69
+
70
+ relevantModules.push(module);
71
+
72
+ // Module must not be the entry points
73
+ if(module.getChunks().some(chunk => chunk.entryModule === module)) {
74
+ setBailoutReason(module, "Module is an entry point");
69
75
  continue;
70
76
  }
71
77
 
@@ -73,9 +79,10 @@ class ModuleConcatenationPlugin {
73
79
  const nonHarmonyReasons = module.reasons.filter(reason => !(reason.dependency instanceof HarmonyImportDependency));
74
80
  if(nonHarmonyReasons.length > 0) {
75
81
  const importingModules = new Set(nonHarmonyReasons.map(r => r.module));
76
- setBailoutReason(module, "ModuleConcatenation (inner)", (requestShortener) => {
77
- const names = Array.from(importingModules).map(m => m.readableIdentifier(requestShortener)).sort();
78
- return `module is used with non-harmony imports from ${names.join(", ")}`;
82
+ const importingModuleTypes = new Map(Array.from(importingModules).map(m => [m, new Set(nonHarmonyReasons.filter(r => r.module === m).map(r => r.dependency.type).sort())]));
83
+ setBailoutReason(module, (requestShortener) => {
84
+ const names = Array.from(importingModules).map(m => `${m.readableIdentifier(requestShortener)} (referenced with ${Array.from(importingModuleTypes.get(m)).join(", ")})`).sort();
85
+ return `Module is referenced from these modules with unsupported syntax: ${names.join(", ")}`;
79
86
  });
80
87
  continue;
81
88
  }
@@ -83,7 +90,7 @@ class ModuleConcatenationPlugin {
83
90
  possibleInners.add(module);
84
91
  }
85
92
  // sort by depth
86
- // modules with lower depth are more likly suited as roots
93
+ // modules with lower depth are more likely suited as roots
87
94
  // this improves performance, because modules already selected as inner are skipped
88
95
  relevantModules.sort((a, b) => {
89
96
  return a.depth - b.depth;
@@ -129,22 +136,20 @@ class ModuleConcatenationPlugin {
129
136
  for(const concatConfiguration of concatConfigurations) {
130
137
  if(usedModules.has(concatConfiguration.rootModule))
131
138
  continue;
132
- const orderedModules = new Set();
133
- this.addInOrder(concatConfiguration.rootModule, concatConfiguration.modules, orderedModules);
134
- const newModule = new ConcatenatedModule(concatConfiguration.rootModule, Array.from(orderedModules));
139
+ const newModule = new ConcatenatedModule(concatConfiguration.rootModule, Array.from(concatConfiguration.modules));
135
140
  concatConfiguration.sortWarnings();
136
141
  for(const warning of concatConfiguration.warnings) {
137
142
  newModule.optimizationBailout.push((requestShortener) => {
138
143
  const reason = getBailoutReason(warning[0], requestShortener);
139
- const reasonPrefix = reason ? `: ${reason}` : "";
144
+ const reasonWithPrefix = reason ? ` (<- ${reason})` : "";
140
145
  if(warning[0] === warning[1])
141
- return `ModuleConcatenation: Cannot concat with ${warning[0].readableIdentifier(requestShortener)}${reasonPrefix}`;
146
+ return formatBailoutReason(`Cannot concat with ${warning[0].readableIdentifier(requestShortener)}${reasonWithPrefix}`);
142
147
  else
143
- return `ModuleConcatenation: Cannot concat with ${warning[0].readableIdentifier(requestShortener)} because of ${warning[1].readableIdentifier(requestShortener)}${reasonPrefix}`;
148
+ return formatBailoutReason(`Cannot concat with ${warning[0].readableIdentifier(requestShortener)} because of ${warning[1].readableIdentifier(requestShortener)}${reasonWithPrefix}`);
144
149
  });
145
150
  }
146
151
  const chunks = concatConfiguration.rootModule.getChunks();
147
- for(const m of orderedModules) {
152
+ for(const m of concatConfiguration.modules) {
148
153
  usedModules.add(m);
149
154
  chunks.forEach(chunk => chunk.removeModule(m));
150
155
  }
@@ -240,16 +245,6 @@ class ModuleConcatenationPlugin {
240
245
  config.set(testConfig);
241
246
  return null;
242
247
  }
243
-
244
- addInOrder(module, unorderedSet, orderedSet) {
245
- if(orderedSet.has(module)) return;
246
- if(!unorderedSet.has(module)) return;
247
- orderedSet.add(module);
248
- for(const imp of this.getImports(module))
249
- this.addInOrder(imp, unorderedSet, orderedSet);
250
- orderedSet.delete(module);
251
- orderedSet.add(module);
252
- }
253
248
  }
254
249
 
255
250
  class ConcatConfiguration {
@@ -7,10 +7,32 @@ const looksLikeAbsolutePath = (maybeAbsolutePath) => {
7
7
 
8
8
  const normalizePathSeparator = (p) => p.replace(/\\/g, "/");
9
9
 
10
- exports.makePathsRelative = (context, identifier) => {
10
+ const _makePathsRelative = (context, identifier) => {
11
11
  return identifier
12
12
  .split(/([|! ])/)
13
13
  .map(str => looksLikeAbsolutePath(str) ?
14
14
  normalizePathSeparator(path.relative(context, str)) : str)
15
15
  .join("");
16
16
  };
17
+
18
+ exports.makePathsRelative = (context, identifier, cache) => {
19
+ if(!cache) return _makePathsRelative(context, identifier);
20
+
21
+ const relativePaths = cache.relativePaths || (cache.relativePaths = new Map());
22
+
23
+ let cachedResult;
24
+ let contextCache = relativePaths.get(context);
25
+ if(typeof contextCache === "undefined") {
26
+ relativePaths.set(context, contextCache = new Map());
27
+ } else {
28
+ cachedResult = contextCache.get(identifier);
29
+ }
30
+
31
+ if(typeof cachedResult !== "undefined") {
32
+ return cachedResult;
33
+ } else {
34
+ const relativePath = _makePathsRelative(context, identifier);
35
+ contextCache.set(identifier, relativePath);
36
+ return relativePath;
37
+ }
38
+ };
package/lib/webpack.js CHANGED
@@ -58,64 +58,61 @@ webpack.validate = validateSchema.bind(this, webpackOptionsSchema);
58
58
  webpack.validateSchema = validateSchema;
59
59
  webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
60
60
 
61
- function exportPlugins(exports, path, plugins) {
62
- plugins.forEach(name => {
63
- Object.defineProperty(exports, name, {
61
+ function exportPlugins(obj, mappings) {
62
+ Object.keys(mappings).forEach(name => {
63
+ Object.defineProperty(obj, name, {
64
64
  configurable: false,
65
65
  enumerable: true,
66
- get() {
67
- return require(`${path}/${name}`);
68
- }
66
+ get: mappings[name]
69
67
  });
70
68
  });
71
69
  }
72
70
 
73
- exportPlugins(exports, ".", [
74
- "DefinePlugin",
75
- "NormalModuleReplacementPlugin",
76
- "ContextReplacementPlugin",
77
- "IgnorePlugin",
78
- "WatchIgnorePlugin",
79
- "BannerPlugin",
80
- "PrefetchPlugin",
81
- "AutomaticPrefetchPlugin",
82
- "ProvidePlugin",
83
- "HotModuleReplacementPlugin",
84
- "SourceMapDevToolPlugin",
85
- "EvalSourceMapDevToolPlugin",
86
- "EvalDevToolModulePlugin",
87
- "CachePlugin",
88
- "ExtendedAPIPlugin",
89
- "ExternalsPlugin",
90
- "JsonpTemplatePlugin",
91
- "LibraryTemplatePlugin",
92
- "LoaderTargetPlugin",
93
- "MemoryOutputFileSystem",
94
- "ProgressPlugin",
95
- "SetVarMainTemplatePlugin",
96
- "UmdMainTemplatePlugin",
97
- "NoErrorsPlugin",
98
- "NoEmitOnErrorsPlugin",
99
- "NewWatchingPlugin",
100
- "EnvironmentPlugin",
101
- "DllPlugin",
102
- "DllReferencePlugin",
103
- "LoaderOptionsPlugin",
104
- "NamedModulesPlugin",
105
- "NamedChunksPlugin",
106
- "HashedModuleIdsPlugin",
107
- "ModuleFilenameHelpers"
108
- ]);
109
- exportPlugins(exports.optimize = {}, "./optimize", [
110
- "AggressiveMergingPlugin",
111
- "AggressiveSplittingPlugin",
112
- "CommonsChunkPlugin",
113
- "ChunkModuleIdRangePlugin",
114
- "DedupePlugin",
115
- "LimitChunkCountPlugin",
116
- "MinChunkSizePlugin",
117
- "ModuleConcatenationPlugin",
118
- "OccurrenceOrderPlugin",
119
- "UglifyJsPlugin"
120
- ]);
121
- exportPlugins(exports.dependencies = {}, "./dependencies", []);
71
+ exportPlugins(exports, {
72
+ "DefinePlugin": () => require("./DefinePlugin"),
73
+ "NormalModuleReplacementPlugin": () => require("./NormalModuleReplacementPlugin"),
74
+ "ContextReplacementPlugin": () => require("./ContextReplacementPlugin"),
75
+ "IgnorePlugin": () => require("./IgnorePlugin"),
76
+ "WatchIgnorePlugin": () => require("./WatchIgnorePlugin"),
77
+ "BannerPlugin": () => require("./BannerPlugin"),
78
+ "PrefetchPlugin": () => require("./PrefetchPlugin"),
79
+ "AutomaticPrefetchPlugin": () => require("./AutomaticPrefetchPlugin"),
80
+ "ProvidePlugin": () => require("./ProvidePlugin"),
81
+ "HotModuleReplacementPlugin": () => require("./HotModuleReplacementPlugin"),
82
+ "SourceMapDevToolPlugin": () => require("./SourceMapDevToolPlugin"),
83
+ "EvalSourceMapDevToolPlugin": () => require("./EvalSourceMapDevToolPlugin"),
84
+ "EvalDevToolModulePlugin": () => require("./EvalDevToolModulePlugin"),
85
+ "CachePlugin": () => require("./CachePlugin"),
86
+ "ExtendedAPIPlugin": () => require("./ExtendedAPIPlugin"),
87
+ "ExternalsPlugin": () => require("./ExternalsPlugin"),
88
+ "JsonpTemplatePlugin": () => require("./JsonpTemplatePlugin"),
89
+ "LibraryTemplatePlugin": () => require("./LibraryTemplatePlugin"),
90
+ "LoaderTargetPlugin": () => require("./LoaderTargetPlugin"),
91
+ "MemoryOutputFileSystem": () => require("./MemoryOutputFileSystem"),
92
+ "ProgressPlugin": () => require("./ProgressPlugin"),
93
+ "SetVarMainTemplatePlugin": () => require("./SetVarMainTemplatePlugin"),
94
+ "UmdMainTemplatePlugin": () => require("./UmdMainTemplatePlugin"),
95
+ "NoErrorsPlugin": () => require("./NoErrorsPlugin"),
96
+ "NoEmitOnErrorsPlugin": () => require("./NoEmitOnErrorsPlugin"),
97
+ "NewWatchingPlugin": () => require("./NewWatchingPlugin"),
98
+ "EnvironmentPlugin": () => require("./EnvironmentPlugin"),
99
+ "DllPlugin": () => require("./DllPlugin"),
100
+ "DllReferencePlugin": () => require("./DllReferencePlugin"),
101
+ "LoaderOptionsPlugin": () => require("./LoaderOptionsPlugin"),
102
+ "NamedModulesPlugin": () => require("./NamedModulesPlugin"),
103
+ "NamedChunksPlugin": () => require("./NamedChunksPlugin"),
104
+ "HashedModuleIdsPlugin": () => require("./HashedModuleIdsPlugin"),
105
+ "ModuleFilenameHelpers": () => require("./ModuleFilenameHelpers")
106
+ });
107
+ exportPlugins(exports.optimize = {}, {
108
+ "AggressiveMergingPlugin": () => require("./optimize/AggressiveMergingPlugin"),
109
+ "AggressiveSplittingPlugin": () => require("./optimize/AggressiveSplittingPlugin"),
110
+ "CommonsChunkPlugin": () => require("./optimize/CommonsChunkPlugin"),
111
+ "ChunkModuleIdRangePlugin": () => require("./optimize/ChunkModuleIdRangePlugin"),
112
+ "DedupePlugin": () => require("./optimize/DedupePlugin"),
113
+ "LimitChunkCountPlugin": () => require("./optimize/LimitChunkCountPlugin"),
114
+ "MinChunkSizePlugin": () => require("./optimize/MinChunkSizePlugin"),
115
+ "ModuleConcatenationPlugin": () => require("./optimize/ModuleConcatenationPlugin"),
116
+ "OccurrenceOrderPlugin": () => require("./optimize/OccurrenceOrderPlugin"),
117
+ "UglifyJsPlugin": () => require("./optimize/UglifyJsPlugin")
118
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "3.3.0",
3
+ "version": "3.5.1",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "dependencies": {
@@ -9,7 +9,7 @@
9
9
  "ajv": "^5.1.5",
10
10
  "ajv-keywords": "^2.0.0",
11
11
  "async": "^2.1.2",
12
- "enhanced-resolve": "^3.3.0",
12
+ "enhanced-resolve": "^3.4.0",
13
13
  "escope": "^3.6.0",
14
14
  "interpret": "^1.0.0",
15
15
  "json-loader": "^0.5.4",
@@ -20,12 +20,12 @@
20
20
  "mkdirp": "~0.5.0",
21
21
  "node-libs-browser": "^2.0.0",
22
22
  "source-map": "^0.5.3",
23
- "supports-color": "^3.1.0",
24
- "tapable": "~0.2.5",
23
+ "supports-color": "^4.2.1",
24
+ "tapable": "^0.2.7",
25
25
  "uglifyjs-webpack-plugin": "^0.4.6",
26
26
  "watchpack": "^1.4.0",
27
27
  "webpack-sources": "^1.0.1",
28
- "yargs": "^6.0.0"
28
+ "yargs": "^8.0.2"
29
29
  },
30
30
  "license": "MIT",
31
31
  "devDependencies": {
@@ -39,12 +39,12 @@
39
39
  "coveralls": "^2.11.2",
40
40
  "css-loader": "^0.28.3",
41
41
  "es6-promise-polyfill": "^1.1.1",
42
- "eslint": "3.12.2",
43
- "eslint-plugin-node": "^3.0.5",
42
+ "eslint": "^4.3.0",
43
+ "eslint-plugin-node": "^5.1.1",
44
44
  "express": "~4.13.1",
45
- "extract-text-webpack-plugin": "^2.0.0-beta",
46
- "file-loader": "^0.11.1",
47
- "i18n-webpack-plugin": "^0.3.0",
45
+ "extract-text-webpack-plugin": "^3.0.0",
46
+ "file-loader": "^0.11.2",
47
+ "i18n-webpack-plugin": "^1.0.0",
48
48
  "istanbul": "^0.4.5",
49
49
  "jade": "^1.11.0",
50
50
  "jade-loader": "~0.8.0",
@@ -743,7 +743,7 @@
743
743
  }
744
744
  ]
745
745
  },
746
- "warning-filters-types": {
746
+ "filter-item-types": {
747
747
  "anyOf": [
748
748
  {
749
749
  "instanceof": "RegExp"
@@ -755,6 +755,19 @@
755
755
  "instanceof": "Function"
756
756
  }
757
757
  ]
758
+ },
759
+ "filter-types": {
760
+ "anyOf": [
761
+ {
762
+ "$ref": "#/definitions/filter-item-types"
763
+ },
764
+ {
765
+ "type": "array",
766
+ "items": {
767
+ "$ref": "#/definitions/filter-item-types"
768
+ }
769
+ }
770
+ ]
758
771
  }
759
772
  },
760
773
  "properties": {
@@ -1009,17 +1022,19 @@
1009
1022
  },
1010
1023
  "warningsFilter": {
1011
1024
  "description": "Suppress warnings that match the specified filters. Filters can be Strings, RegExps or Functions",
1012
- "anyOf": [
1013
- {
1014
- "type": "array",
1015
- "items": {
1016
- "$ref": "#/definitions/warning-filters-types"
1017
- }
1018
- },
1019
- {
1020
- "$ref": "#/definitions/warning-filters-types"
1021
- }
1022
- ]
1025
+ "$ref": "#/definitions/filter-types"
1026
+ },
1027
+ "excludeAssets": {
1028
+ "description": "Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions",
1029
+ "$ref": "#/definitions/filter-types"
1030
+ },
1031
+ "excludeModules": {
1032
+ "description": "Suppress modules that match the specified filters. Filters can be Strings, RegExps or Functions",
1033
+ "$ref": "#/definitions/filter-types"
1034
+ },
1035
+ "exclude": {
1036
+ "description": "Please use excludeModules instead.",
1037
+ "$ref": "#/definitions/filter-types"
1023
1038
  },
1024
1039
  "errorDetails": {
1025
1040
  "type": "boolean",