webpack 2.3.1 → 2.4.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 (77) hide show
  1. package/README.md +139 -132
  2. package/lib/APIPlugin.js +0 -6
  3. package/lib/AsyncDependenciesBlock.js +1 -1
  4. package/lib/AutomaticPrefetchPlugin.js +2 -2
  5. package/lib/CachePlugin.js +2 -2
  6. package/lib/CaseSensitiveModulesWarning.js +6 -3
  7. package/lib/ChunkRenderError.js +3 -1
  8. package/lib/ChunkTemplate.js +2 -2
  9. package/lib/Compilation.js +3 -3
  10. package/lib/Compiler.js +1 -1
  11. package/lib/ContextModule.js +3 -2
  12. package/lib/ContextModuleFactory.js +5 -5
  13. package/lib/DelegatedModule.js +67 -63
  14. package/lib/DependenciesBlock.js +65 -59
  15. package/lib/Dependency.js +1 -0
  16. package/lib/EntryModuleNotFoundError.js +16 -10
  17. package/lib/ExtendedAPIPlugin.js +7 -2
  18. package/lib/ExternalModuleFactoryPlugin.js +26 -23
  19. package/lib/FlagDependencyUsagePlugin.js +63 -75
  20. package/lib/HotModuleReplacement.runtime.js +25 -27
  21. package/lib/HotModuleReplacementPlugin.js +3 -5
  22. package/lib/IgnorePlugin.js +48 -17
  23. package/lib/JsonpChunkTemplatePlugin.js +24 -24
  24. package/lib/JsonpMainTemplatePlugin.js +182 -182
  25. package/lib/LibManifestPlugin.js +51 -46
  26. package/lib/MainTemplate.js +17 -18
  27. package/lib/Module.js +158 -160
  28. package/lib/ModuleBuildError.js +4 -2
  29. package/lib/ModuleDependencyError.js +2 -1
  30. package/lib/ModuleDependencyWarning.js +2 -1
  31. package/lib/ModuleError.js +2 -2
  32. package/lib/ModuleFilenameHelpers.js +27 -27
  33. package/lib/ModuleNotFoundError.js +3 -1
  34. package/lib/ModuleParseError.js +6 -4
  35. package/lib/ModuleWarning.js +2 -2
  36. package/lib/MultiCompiler.js +3 -4
  37. package/lib/MultiStats.js +3 -3
  38. package/lib/MultiWatching.js +2 -2
  39. package/lib/NamedChunksPlugin.js +30 -0
  40. package/lib/NodeStuffPlugin.js +80 -79
  41. package/lib/NormalModule.js +6 -2
  42. package/lib/NormalModuleFactory.js +244 -240
  43. package/lib/Parser.js +1256 -1079
  44. package/lib/ProgressPlugin.js +1 -1
  45. package/lib/RecordIdsPlugin.js +5 -9
  46. package/lib/SetVarMainTemplatePlugin.js +1 -1
  47. package/lib/SourceMapDevToolPlugin.js +153 -157
  48. package/lib/Stats.js +32 -5
  49. package/lib/TemplatedPathPlugin.js +1 -0
  50. package/lib/UnsupportedFeatureWarning.js +2 -1
  51. package/lib/WebpackError.js +11 -0
  52. package/lib/WebpackOptionsApply.js +1 -1
  53. package/lib/WebpackOptionsValidationError.js +8 -4
  54. package/lib/dependencies/AMDDefineDependency.js +10 -6
  55. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
  56. package/lib/dependencies/AMDPlugin.js +3 -3
  57. package/lib/dependencies/ContextDependencyHelpers.js +19 -16
  58. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  59. package/lib/dependencies/DepBlockHelpers.js +3 -3
  60. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -2
  61. package/lib/dependencies/ImportContextDependency.js +2 -1
  62. package/lib/dependencies/ImportDependenciesBlock.js +2 -2
  63. package/lib/dependencies/ImportParserPlugin.js +16 -2
  64. package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
  65. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
  66. package/lib/dependencies/RequireEnsureDependency.js +9 -2
  67. package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
  68. package/lib/optimize/CommonsChunkPlugin.js +1 -1
  69. package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
  70. package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
  71. package/lib/performance/NoAsyncChunksWarning.js +5 -1
  72. package/lib/removeAndDo.js +6 -4
  73. package/lib/util/identifier.js +16 -0
  74. package/lib/webpack.js +2 -1
  75. package/package.json +4 -3
  76. package/schemas/ajv.absolutePath.js +1 -1
  77. package/schemas/webpackOptionsSchema.json +27 -0
@@ -2,7 +2,7 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var async = require("async");
5
+ var asyncLib = require("async");
6
6
  var path = require("path");
7
7
 
8
8
  var Tapable = require("tapable");
@@ -61,7 +61,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
61
61
 
62
62
  var resolvers = module.resolvers;
63
63
 
64
- async.parallel([
64
+ asyncLib.parallel([
65
65
  function(callback) {
66
66
  resolvers.context.resolve({}, context, resource, function(err, result) {
67
67
  if(err) return callback(err);
@@ -69,7 +69,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
69
69
  });
70
70
  },
71
71
  function(callback) {
72
- async.map(loaders, function(loader, callback) {
72
+ asyncLib.map(loaders, function(loader, callback) {
73
73
  resolvers.loader.resolve({}, context, loader, function(err, result) {
74
74
  if(err) return callback(err);
75
75
  callback(null, result);
@@ -93,7 +93,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
93
93
  // Ignored
94
94
  if(!result) return callback();
95
95
 
96
- return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async));
96
+ return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async, dependency.chunkName));
97
97
  });
98
98
  });
99
99
  });
@@ -106,7 +106,7 @@ ContextModuleFactory.prototype.resolveDependencies = function resolveDependencie
106
106
  fs.readdir(directory, function(err, files) {
107
107
  if(err) return callback(err);
108
108
  if(!files || files.length === 0) return callback(null, []);
109
- async.map(files.filter(function(p) {
109
+ asyncLib.map(files.filter(function(p) {
110
110
  return p.indexOf(".") !== 0;
111
111
  }), function(seqment, callback) {
112
112
 
@@ -2,79 +2,83 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var Module = require("./Module");
6
- var OriginalSource = require("webpack-sources").OriginalSource;
7
- var RawSource = require("webpack-sources").RawSource;
8
- var WebpackMissingModule = require("./dependencies/WebpackMissingModule");
9
- var DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
5
+ "use strict";
10
6
 
11
- function DelegatedModule(sourceRequest, data, type, userRequest) {
12
- Module.call(this);
13
- this.sourceRequest = sourceRequest;
14
- this.request = data.id;
15
- this.meta = data.meta;
16
- this.type = type;
17
- this.userRequest = userRequest;
18
- this.built = false;
19
- this.delegateData = data;
20
- }
21
- module.exports = DelegatedModule;
7
+ const Module = require("./Module");
8
+ const OriginalSource = require("webpack-sources").OriginalSource;
9
+ const RawSource = require("webpack-sources").RawSource;
10
+ const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
11
+ const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
12
+
13
+ class DelegatedModule extends Module {
14
+ constructor(sourceRequest, data, type, userRequest) {
15
+ super();
16
+ this.sourceRequest = sourceRequest;
17
+ this.request = data.id;
18
+ this.meta = data.meta;
19
+ this.type = type;
20
+ this.userRequest = userRequest;
21
+ this.built = false;
22
+ this.delegated = true;
23
+ this.delegateData = data;
24
+ }
22
25
 
23
- DelegatedModule.prototype = Object.create(Module.prototype);
24
- DelegatedModule.prototype.constructor = DelegatedModule;
26
+ identifier() {
27
+ return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
28
+ }
29
+
30
+ readableIdentifier() {
31
+ return `delegated ${this.userRequest} from ${this.sourceRequest}`;
32
+ }
25
33
 
26
- DelegatedModule.prototype.delegated = true;
34
+ needRebuild() {
35
+ return false;
36
+ }
27
37
 
28
- DelegatedModule.prototype.identifier = function() {
29
- return "delegated " + JSON.stringify(this.request) + " from " + this.sourceRequest;
30
- };
38
+ build(options, compilation, resolver, fs, callback) {
39
+ this.built = true;
40
+ this.builtTime = new Date().getTime();
41
+ this.usedExports = true;
42
+ this.providedExports = this.delegateData.exports || true;
43
+ this.dependencies.length = 0;
44
+ this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
45
+ callback();
46
+ }
31
47
 
32
- DelegatedModule.prototype.readableIdentifier = function() {
33
- return "delegated " + this.userRequest + " from " + this.sourceRequest;
34
- };
48
+ unbuild() {
49
+ this.built = false;
50
+ super.unbuild();
51
+ }
35
52
 
36
- DelegatedModule.prototype.needRebuild = function() {
37
- return false;
38
- };
53
+ source() {
54
+ const sourceModule = this.dependencies[0].module;
55
+ let str;
39
56
 
40
- DelegatedModule.prototype.build = function(options, compilation, resolver, fs, callback) {
41
- this.built = true;
42
- this.builtTime = new Date().getTime();
43
- this.usedExports = true;
44
- this.providedExports = this.delegateData.exports || true;
45
- this.dependencies.length = 0;
46
- this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
47
- callback();
48
- };
57
+ if(!sourceModule) {
58
+ str = WebpackMissingModule.moduleCode(this.sourceRequest);
59
+ } else {
60
+ str = `module.exports = (__webpack_require__(${sourceModule.id}))`;
49
61
 
50
- DelegatedModule.prototype.unbuild = function() {
51
- this.built = false;
52
- Module.prototype.unbuild.call(this);
53
- };
62
+ switch(this.type) {
63
+ case "require":
64
+ str += `(${JSON.stringify(this.request)})`;
65
+ break;
66
+ case "object":
67
+ str += `[${JSON.stringify(this.request)}]`;
68
+ break;
69
+ }
70
+ }
54
71
 
55
- DelegatedModule.prototype.source = function() {
56
- var sourceModule = this.dependencies[0].module;
57
- var str;
58
- if(!sourceModule) {
59
- str = WebpackMissingModule.moduleCode(this.sourceRequest);
60
- } else {
61
- str = "module.exports = (__webpack_require__(" + sourceModule.id + "))";
62
- switch(this.type) {
63
- case "require":
64
- str += "(" + JSON.stringify(this.request) + ");";
65
- break;
66
- case "object":
67
- str += "[" + JSON.stringify(this.request) + "];";
68
- break;
72
+ if(this.useSourceMap) {
73
+ return new OriginalSource(str, this.identifier());
74
+ } else {
75
+ return new RawSource(str);
69
76
  }
70
77
  }
71
- if(this.useSourceMap) {
72
- return new OriginalSource(str, this.identifier());
73
- } else {
74
- return new RawSource(str);
78
+
79
+ size() {
80
+ return 42;
75
81
  }
76
- };
82
+ }
77
83
 
78
- DelegatedModule.prototype.size = function() {
79
- return 42;
80
- };
84
+ module.exports = DelegatedModule;
@@ -1,75 +1,81 @@
1
1
  /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- var DependenciesBlockVariable = require("./DependenciesBlockVariable");
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
6
 
7
- function DependenciesBlock() {
8
- this.dependencies = [];
9
- this.blocks = [];
10
- this.variables = [];
7
+ const DependenciesBlockVariable = require("./DependenciesBlockVariable");
8
+
9
+ function disconnect(i) {
10
+ i.disconnect();
11
11
  }
12
- module.exports = DependenciesBlock;
13
12
 
14
- DependenciesBlock.prototype.addBlock = function(block) {
15
- this.blocks.push(block);
16
- block.parent = this;
17
- };
13
+ function unseal(i) {
14
+ i.unseal();
15
+ }
16
+
17
+ class DependenciesBlock {
18
+ constructor() {
19
+ this.dependencies = [];
20
+ this.blocks = [];
21
+ this.variables = [];
22
+ }
23
+
24
+ addBlock(block) {
25
+ this.blocks.push(block);
26
+ block.parent = this;
27
+ }
28
+
29
+ addVariable(name, expression, dependencies) {
30
+ for(let v of this.variables) {
31
+ if(v.name === name && v.expression === expression) {
32
+ return;
33
+ }
34
+ }
35
+ this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
36
+ }
18
37
 
19
- DependenciesBlock.prototype.addVariable = function(name, expression, dependencies) {
20
- for(var i = 0; i < this.variables.length; i++) {
21
- var v = this.variables[i];
22
- if(v.name === name && v.expression === expression) return;
38
+ addDependency(dependency) {
39
+ this.dependencies.push(dependency);
23
40
  }
24
- this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
25
- };
26
41
 
27
- DependenciesBlock.prototype.addDependency = function(dependency) {
28
- this.dependencies.push(dependency);
29
- };
42
+ updateHash(hash) {
43
+ function updateHash(i) {
44
+ i.updateHash(hash);
45
+ }
30
46
 
31
- DependenciesBlock.prototype.updateHash = function(hash) {
32
- this.dependencies.forEach(function(d) {
33
- d.updateHash(hash);
34
- });
35
- this.blocks.forEach(function(b) {
36
- b.updateHash(hash);
37
- });
38
- this.variables.forEach(function(v) {
39
- v.updateHash(hash);
40
- });
41
- };
47
+ this.dependencies.forEach(updateHash);
48
+ this.blocks.forEach(updateHash);
49
+ this.variables.forEach(updateHash);
50
+ }
42
51
 
43
- DependenciesBlock.prototype.disconnect = function() {
44
- function disconnect(i) {
45
- i.disconnect();
52
+ disconnect() {
53
+ this.dependencies.forEach(disconnect);
54
+ this.blocks.forEach(disconnect);
55
+ this.variables.forEach(disconnect);
46
56
  }
47
- this.dependencies.forEach(disconnect);
48
- this.blocks.forEach(disconnect);
49
- this.variables.forEach(disconnect);
50
- };
51
57
 
52
- DependenciesBlock.prototype.unseal = function() {
53
- function unseal(i) {
54
- i.unseal();
58
+ unseal() {
59
+ this.blocks.forEach(unseal);
55
60
  }
56
- this.blocks.forEach(unseal);
57
- };
58
61
 
59
- DependenciesBlock.prototype.hasDependencies = function(filter) {
60
- if(filter) {
61
- if(this.dependencies.some(filter)) return true;
62
- } else {
63
- if(this.dependencies.length > 0) return true;
62
+ hasDependencies(filter) {
63
+ if(filter) {
64
+ if(this.dependencies.some(filter)) {
65
+ return true;
66
+ }
67
+ } else {
68
+ if(this.dependencies.length > 0) {
69
+ return true;
70
+ }
71
+ }
72
+
73
+ return this.blocks.concat(this.variables).some(item => item.hasDependencies(filter));
64
74
  }
65
75
 
66
- return this.blocks.concat(this.variables).some(function(item) {
67
- return item.hasDependencies(filter);
68
- });
69
- };
76
+ sortItems() {
77
+ this.blocks.forEach(block => block.sortItems());
78
+ }
79
+ }
70
80
 
71
- DependenciesBlock.prototype.sortItems = function() {
72
- this.blocks.forEach(function(block) {
73
- block.sortItems();
74
- });
75
- };
81
+ module.exports = DependenciesBlock;
package/lib/Dependency.js CHANGED
@@ -44,6 +44,7 @@ class Dependency {
44
44
  this.module = null;
45
45
  }
46
46
 
47
+ // TODO: remove in webpack 3
47
48
  compare(a, b) {
48
49
  return compareLocations(a.loc, b.loc);
49
50
  }
@@ -2,15 +2,21 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- function EntryModuleNotFoundError(err) {
6
- Error.call(this);
7
- this.name = "EntryModuleNotFoundError";
8
- this.message = "Entry module not found: " + err;
9
- this.details = err.details;
10
- this.error = err;
11
- Error.captureStackTrace(this, EntryModuleNotFoundError);
5
+ "use strict";
6
+
7
+ const WebpackError = require("./WebpackError");
8
+
9
+ class EntryModuleNotFoundError extends WebpackError {
10
+ constructor(err) {
11
+ super();
12
+
13
+ this.name = "EntryModuleNotFoundError";
14
+ this.message = "Entry module not found: " + err;
15
+ this.details = err.details;
16
+ this.error = err;
17
+
18
+ Error.captureStackTrace(this, this.constructor);
19
+ }
12
20
  }
13
- module.exports = EntryModuleNotFoundError;
14
21
 
15
- EntryModuleNotFoundError.prototype = Object.create(Error.prototype);
16
- EntryModuleNotFoundError.prototype.constructor = EntryModuleNotFoundError;
22
+ module.exports = EntryModuleNotFoundError;
@@ -9,10 +9,12 @@ const ParserHelpers = require("./ParserHelpers");
9
9
  const NullFactory = require("./NullFactory");
10
10
 
11
11
  const REPLACEMENTS = {
12
- __webpack_hash__: "__webpack_require__.h" // eslint-disable-line camelcase
12
+ __webpack_hash__: "__webpack_require__.h", // eslint-disable-line camelcase
13
+ __webpack_chunkname__: "__webpack_require__.cn" // eslint-disable-line camelcase
13
14
  };
14
15
  const REPLACEMENT_TYPES = {
15
- __webpack_hash__: "string" // eslint-disable-line camelcase
16
+ __webpack_hash__: "string", // eslint-disable-line camelcase
17
+ __webpack_chunkname__: "string" // eslint-disable-line camelcase
16
18
  };
17
19
 
18
20
  class ExtendedAPIPlugin {
@@ -25,6 +27,9 @@ class ExtendedAPIPlugin {
25
27
  buf.push("");
26
28
  buf.push("// __webpack_hash__");
27
29
  buf.push(`${this.requireFn}.h = ${JSON.stringify(hash)};`);
30
+ buf.push("");
31
+ buf.push("// __webpack_chunkname__");
32
+ buf.push(`${this.requireFn}.cn = ${JSON.stringify(chunk.name)};`);
28
33
  return this.asString(buf);
29
34
  });
30
35
  compilation.mainTemplate.plugin("global-hash", () => true);
@@ -2,20 +2,21 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var ExternalModule = require("./ExternalModule");
5
+ "use strict";
6
6
 
7
- function ExternalModuleFactoryPlugin(type, externals) {
8
- this.type = type;
9
- this.externals = externals;
10
- }
11
- module.exports = ExternalModuleFactoryPlugin;
7
+ const ExternalModule = require("./ExternalModule");
8
+
9
+ class ExternalModuleFactoryPlugin {
10
+ constructor(type, externals) {
11
+ this.type = type;
12
+ this.externals = externals;
13
+ }
12
14
 
13
- ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
14
- var globalType = this.type;
15
- normalModuleFactory.plugin("factory", function(factory) {
16
- return function(data, callback) {
17
- var context = data.context;
18
- var dependency = data.dependencies[0];
15
+ apply(normalModuleFactory) {
16
+ const globalType = this.type;
17
+ normalModuleFactory.plugin("factory", factory => (data, callback) => {
18
+ const context = data.context;
19
+ const dependency = data.dependencies[0];
19
20
 
20
21
  function handleExternal(value, type, callback) {
21
22
  if(typeof type === "function") {
@@ -25,7 +26,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
25
26
  if(value === false) return factory(data, callback);
26
27
  if(value === true) value = dependency.request;
27
28
  if(typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
28
- var idx = value.indexOf(" ");
29
+ const idx = value.indexOf(" ");
29
30
  type = value.substr(0, idx);
30
31
  value = value.substr(idx + 1);
31
32
  }
@@ -38,13 +39,14 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
38
39
  return handleExternal(dependency.request, callback);
39
40
  }
40
41
  } else if(Array.isArray(externals)) {
41
- var i = 0;
42
+ let i = 0;
42
43
  (function next() {
43
- var handleExternalsAndCallback = function handleExternalsAndCallback(err, module) {
44
+ let asyncFlag;
45
+ const handleExternalsAndCallback = function handleExternalsAndCallback(err, module) {
44
46
  if(err) return callback(err);
45
47
  if(!module) {
46
- if(async) {
47
- async = false;
48
+ if(asyncFlag) {
49
+ asyncFlag = false;
48
50
  return;
49
51
  }
50
52
  return next();
@@ -53,11 +55,11 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
53
55
  };
54
56
 
55
57
  do {
56
- var async = true;
58
+ asyncFlag = true;
57
59
  if(i >= externals.length) return callback();
58
60
  handleExternals(externals[i++], handleExternalsAndCallback);
59
- } while (!async); // eslint-disable-line keyword-spacing
60
- async = false;
61
+ } while (!asyncFlag); // eslint-disable-line keyword-spacing
62
+ asyncFlag = false;
61
63
  }());
62
64
  return;
63
65
  } else if(externals instanceof RegExp) {
@@ -83,6 +85,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
83
85
  if(!module) return handleExternal(false, callback);
84
86
  return callback(null, module);
85
87
  }));
86
- }.bind(this);
87
- }.bind(this));
88
- };
88
+ });
89
+ }
90
+ }
91
+ module.exports = ExternalModuleFactoryPlugin;
@@ -2,92 +2,80 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- function FlagDependencyUsagePlugin() {
5
+ "use strict";
6
6
 
7
- }
8
- module.exports = FlagDependencyUsagePlugin;
7
+ class FlagDependencyUsagePlugin {
8
+ apply(compiler) {
9
+ compiler.plugin("compilation", compilation => {
10
+ compilation.plugin("optimize-modules-advanced", modules => {
9
11
 
10
- FlagDependencyUsagePlugin.prototype.apply = function(compiler) {
11
- compiler.plugin("compilation", function(compilation) {
12
- compilation.plugin("optimize-modules-advanced", function(modules) {
12
+ modules.forEach(module => module.used = false);
13
13
 
14
- modules.forEach(function(module) {
15
- module.used = false;
16
- });
14
+ const queue = [];
15
+ compilation.chunks.forEach(chunk => {
16
+ if(chunk.entryModule) {
17
+ processModule(chunk.entryModule, true);
18
+ }
19
+ });
17
20
 
18
- var queue = [];
19
- compilation.chunks.forEach(function(chunk) {
20
- if(chunk.entryModule) {
21
- processModule(chunk.entryModule, true);
21
+ while(queue.length) {
22
+ const queueItem = queue.pop();
23
+ processDependenciesBlock(queueItem[0], queueItem[1]);
22
24
  }
23
- });
24
-
25
- while(queue.length) {
26
- var queueItem = queue.pop();
27
- processDependenciesBlock(queueItem[0], queueItem[1]);
28
- }
29
25
 
30
- function processModule(module, usedExports) {
31
- module.used = true;
32
- if(module.usedExports === true)
33
- return;
34
- else if(usedExports === true)
35
- module.usedExports = true;
36
- else if(Array.isArray(usedExports)) {
37
- var old = module.usedExports ? module.usedExports.length : -1;
38
- module.usedExports = addToSet(module.usedExports || [], usedExports);
39
- if(module.usedExports.length === old)
26
+ function processModule(module, usedExports) {
27
+ module.used = true;
28
+ if(module.usedExports === true)
40
29
  return;
41
- } else if(Array.isArray(module.usedExports))
42
- return;
43
- else
44
- module.usedExports = false;
45
-
46
- queue.push([module, module.usedExports]);
47
- }
30
+ else if(usedExports === true)
31
+ module.usedExports = true;
32
+ else if(Array.isArray(usedExports)) {
33
+ var old = module.usedExports ? module.usedExports.length : -1;
34
+ module.usedExports = addToSet(module.usedExports || [], usedExports);
35
+ if(module.usedExports.length === old)
36
+ return;
37
+ } else if(Array.isArray(module.usedExports))
38
+ return;
39
+ else
40
+ module.usedExports = false;
48
41
 
49
- function processDependenciesBlock(depBlock, usedExports) {
50
- depBlock.dependencies.forEach(function(dep) {
51
- processDependency(dep, usedExports);
52
- });
53
- depBlock.variables.forEach(function(variable) {
54
- variable.dependencies.forEach(function(dep) {
55
- processDependency(dep, usedExports);
56
- });
57
- });
58
- depBlock.blocks.forEach(function(block) {
59
- queue.push([block, usedExports]);
60
- });
61
- }
42
+ queue.push([module, module.usedExports]);
43
+ }
62
44
 
63
- function processDependency(dep, usedExports) {
64
- var reference = dep.getReference && dep.getReference();
65
- if(!reference) return;
66
- var module = reference.module;
67
- var importedNames = reference.importedNames;
68
- var oldUsed = module.used;
69
- var oldUsedExports = module.usedExports;
70
- if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
71
- processModule(module, importedNames);
45
+ function processDependenciesBlock(depBlock, usedExports) {
46
+ depBlock.dependencies.forEach(dep => processDependency(dep));
47
+ depBlock.variables.forEach(variable => variable.dependencies.forEach(dep => processDependency(dep)));
48
+ depBlock.blocks.forEach(block => queue.push([block, usedExports]));
72
49
  }
73
- }
74
50
 
75
- });
51
+ function processDependency(dep) {
52
+ const reference = dep.getReference && dep.getReference();
53
+ if(!reference) return;
54
+ const module = reference.module;
55
+ const importedNames = reference.importedNames;
56
+ const oldUsed = module.used;
57
+ const oldUsedExports = module.usedExports;
58
+ if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
59
+ processModule(module, importedNames);
60
+ }
61
+ }
76
62
 
77
- function addToSet(a, b) {
78
- b.forEach(function(item) {
79
- if(a.indexOf(item) < 0)
80
- a.push(item);
81
63
  });
82
- return a;
83
- }
84
64
 
85
- function isSubset(biggerSet, subset) {
86
- if(biggerSet === true) return true;
87
- if(subset === true) return false;
88
- return subset.every(function(item) {
89
- return biggerSet.indexOf(item) >= 0;
90
- });
91
- }
92
- });
93
- };
65
+ function addToSet(a, b) {
66
+ b.forEach(item => {
67
+ if(a.indexOf(item) < 0)
68
+ a.push(item);
69
+ });
70
+ return a;
71
+ }
72
+
73
+ function isSubset(biggerSet, subset) {
74
+ if(biggerSet === true) return true;
75
+ if(subset === true) return false;
76
+ return subset.every(item => biggerSet.indexOf(item) >= 0);
77
+ }
78
+ });
79
+ }
80
+ }
81
+ module.exports = FlagDependencyUsagePlugin;