webpack 2.1.0-beta.21 → 2.1.0-beta.25

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 (66) hide show
  1. package/bin/config-yargs.js +6 -5
  2. package/bin/convert-argv.js +59 -31
  3. package/bin/webpack.js +30 -2
  4. package/lib/APIPlugin.js +19 -16
  5. package/lib/Chunk.js +1 -1
  6. package/lib/CommonJsHarmonyMainTemplatePlugin.js +21 -0
  7. package/lib/CompatibilityPlugin.js +24 -17
  8. package/lib/Compilation.js +36 -15
  9. package/lib/Compiler.js +48 -15
  10. package/lib/ConstPlugin.js +40 -37
  11. package/lib/DefinePlugin.js +107 -103
  12. package/lib/DelegatedModule.js +1 -2
  13. package/lib/Dependency.js +5 -0
  14. package/lib/DllReferencePlugin.js +41 -15
  15. package/lib/ExtendedAPIPlugin.js +14 -11
  16. package/lib/FlagDependencyExportsPlugin.js +102 -0
  17. package/lib/FlagInitialModulesAsUsedPlugin.js +23 -23
  18. package/lib/FunctionModuleTemplatePlugin.js +4 -0
  19. package/lib/HotModuleReplacement.runtime.js +1 -1
  20. package/lib/HotModuleReplacementPlugin.js +71 -68
  21. package/lib/LibManifestPlugin.js +1 -2
  22. package/lib/LibraryTemplatePlugin.js +4 -0
  23. package/lib/MainTemplate.js +12 -13
  24. package/lib/Module.js +10 -1
  25. package/lib/MovedToPluginWarningPlugin.js +3 -1
  26. package/lib/MultiCompiler.js +81 -7
  27. package/lib/NodeStuffPlugin.js +97 -86
  28. package/lib/NormalModule.js +6 -0
  29. package/lib/NormalModuleFactory.js +87 -34
  30. package/lib/Parser.js +13 -4
  31. package/lib/ProvidePlugin.js +30 -27
  32. package/lib/RequireJsStuffPlugin.js +27 -21
  33. package/lib/RuleSet.js +369 -0
  34. package/lib/Stats.js +74 -90
  35. package/lib/UseStrictPlugin.js +12 -8
  36. package/lib/WebpackOptionsApply.js +3 -13
  37. package/lib/WebpackOptionsDefaulter.js +0 -1
  38. package/lib/WebpackOptionsValidationError.js +186 -0
  39. package/lib/dependencies/AMDPlugin.js +64 -55
  40. package/lib/dependencies/CommonJsPlugin.js +55 -45
  41. package/lib/dependencies/HarmonyExportExpressionDependency.js +6 -0
  42. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +76 -16
  43. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -4
  44. package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -4
  45. package/lib/dependencies/HarmonyModulesHelpers.js +0 -29
  46. package/lib/dependencies/HarmonyModulesPlugin.js +11 -4
  47. package/lib/dependencies/RequireContextPlugin.js +12 -5
  48. package/lib/dependencies/RequireEnsurePlugin.js +17 -10
  49. package/lib/dependencies/RequireIncludePlugin.js +18 -10
  50. package/lib/dependencies/SystemPlugin.js +48 -29
  51. package/lib/node/NodeMainTemplate.runtime.js +2 -2
  52. package/lib/node/NodeMainTemplateAsync.runtime.js +2 -2
  53. package/lib/node/NodeSourcePlugin.js +84 -71
  54. package/lib/optimize/ChunkModuleIdRangePlugin.js +52 -0
  55. package/lib/optimize/EnsureChunkConditionsPlugin.js +7 -2
  56. package/lib/validateWebpackOptions.js +63 -0
  57. package/lib/webpack.js +9 -6
  58. package/lib/webworker/WebWorkerMainTemplate.runtime.js +35 -33
  59. package/package.json +13 -8
  60. package/schemas/webpackOptionsSchema.json +802 -0
  61. package/README.md +0 -315
  62. package/lib/LoadersList.js +0 -110
  63. package/lib/dependencies/LabeledExportsDependency.js +0 -21
  64. package/lib/dependencies/LabeledModuleDependency.js +0 -36
  65. package/lib/dependencies/LabeledModuleDependencyParserPlugin.js +0 -78
  66. package/lib/dependencies/LabeledModulesPlugin.js +0 -26
@@ -46,9 +46,16 @@ HarmonyModulesPlugin.prototype.apply = function(compiler) {
46
46
 
47
47
  compilation.dependencyFactories.set(HarmonyAcceptImportDependency, normalModuleFactory);
48
48
  compilation.dependencyTemplates.set(HarmonyAcceptImportDependency, new HarmonyAcceptImportDependency.Template());
49
+
50
+ params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
51
+
52
+ if(typeof parserOptions.harmony !== "undefined" && !parserOptions.harmony)
53
+ return;
54
+
55
+ parser.apply(
56
+ new HarmonyImportDependencyParserPlugin(),
57
+ new HarmonyExportDependencyParserPlugin()
58
+ );
59
+ });
49
60
  });
50
- compiler.parser.apply(
51
- new HarmonyImportDependencyParserPlugin(),
52
- new HarmonyExportDependencyParserPlugin()
53
- );
54
61
  };
@@ -28,9 +28,16 @@ RequireContextPlugin.prototype.apply = function(compiler) {
28
28
  compilation.dependencyTemplates.set(RequireContextDependency, new RequireContextDependency.Template());
29
29
 
30
30
  compilation.dependencyFactories.set(ContextElementDependency, normalModuleFactory);
31
- });
32
- compiler.plugin("context-module-factory", function(cmf) {
33
- cmf.plugin("alternatives", function(items, callback) {
31
+
32
+ params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
33
+
34
+ if(typeof parserOptions.requireContext !== "undefined" && !parserOptions.requireContext)
35
+ return;
36
+
37
+ parser.apply(new RequireContextDependencyParserPlugin());
38
+ });
39
+
40
+ params.contextModuleFactory.plugin("alternatives", function(items, callback) {
34
41
  if(items.length === 0) return callback(null, items);
35
42
 
36
43
  callback(null, items.map(function(obj) {
@@ -48,7 +55,8 @@ RequireContextPlugin.prototype.apply = function(compiler) {
48
55
  return a.concat(b);
49
56
  }, []));
50
57
  });
51
- cmf.plugin("alternatives", function(items, callback) {
58
+
59
+ params.contextModuleFactory.plugin("alternatives", function(items, callback) {
52
60
  if(items.length === 0) return callback(null, items);
53
61
 
54
62
  callback(null, items.map(function(obj) {
@@ -64,5 +72,4 @@ RequireContextPlugin.prototype.apply = function(compiler) {
64
72
  }));
65
73
  });
66
74
  });
67
- new RequireContextDependencyParserPlugin().apply(compiler.parser);
68
75
  };
@@ -24,15 +24,22 @@ RequireEnsurePlugin.prototype.apply = function(compiler) {
24
24
 
25
25
  compilation.dependencyFactories.set(RequireEnsureDependency, new NullFactory());
26
26
  compilation.dependencyTemplates.set(RequireEnsureDependency, new RequireEnsureDependency.Template());
27
- });
28
- new RequireEnsureDependenciesBlockParserPlugin().apply(compiler.parser);
29
- compiler.parser.plugin("evaluate typeof require.ensure", function(expr) {
30
- return new BasicEvaluatedExpression().setString("function").setRange(expr.range);
31
- });
32
- compiler.parser.plugin("typeof require.ensure", function(expr) {
33
- var dep = new ConstDependency("'function'", expr.range);
34
- dep.loc = expr.loc;
35
- this.state.current.addDependency(dep);
36
- return true;
27
+
28
+ params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
29
+
30
+ if(typeof parserOptions.requireEnsure !== "undefined" && !parserOptions.requireEnsure)
31
+ return;
32
+
33
+ parser.apply(new RequireEnsureDependenciesBlockParserPlugin());
34
+ parser.plugin("evaluate typeof require.ensure", function(expr) {
35
+ return new BasicEvaluatedExpression().setString("function").setRange(expr.range);
36
+ });
37
+ parser.plugin("typeof require.ensure", function(expr) {
38
+ var dep = new ConstDependency("'function'", expr.range);
39
+ dep.loc = expr.loc;
40
+ this.state.current.addDependency(dep);
41
+ return true;
42
+ });
43
+ });
37
44
  });
38
45
  };
@@ -17,15 +17,23 @@ RequireIncludePlugin.prototype.apply = function(compiler) {
17
17
 
18
18
  compilation.dependencyFactories.set(RequireIncludeDependency, normalModuleFactory);
19
19
  compilation.dependencyTemplates.set(RequireIncludeDependency, new RequireIncludeDependency.Template());
20
- });
21
- new RequireIncludeDependencyParserPlugin().apply(compiler.parser);
22
- compiler.parser.plugin("evaluate typeof require.include", function(expr) {
23
- return new BasicEvaluatedExpression().setString("function").setRange(expr.range);
24
- });
25
- compiler.parser.plugin("typeof require.include", function(expr) {
26
- var dep = new ConstDependency("'function'", expr.range);
27
- dep.loc = expr.loc;
28
- this.state.current.addDependency(dep);
29
- return true;
20
+
21
+ params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
22
+
23
+ if(typeof parserOptions.requireInclude !== "undefined" && !parserOptions.requireInclude)
24
+ return;
25
+
26
+ parser.apply(new RequireIncludeDependencyParserPlugin());
27
+ parser.plugin("evaluate typeof require.include", function(expr) {
28
+ return new BasicEvaluatedExpression().setString("function").setRange(expr.range);
29
+ });
30
+ parser.plugin("typeof require.include", function(expr) {
31
+ var dep = new ConstDependency("'function'", expr.range);
32
+ dep.loc = expr.loc;
33
+ this.state.current.addDependency(dep);
34
+ return true;
35
+ });
36
+
37
+ });
30
38
  });
31
39
  };
@@ -17,28 +17,7 @@ function SystemPlugin(options) {
17
17
  module.exports = SystemPlugin;
18
18
 
19
19
  SystemPlugin.prototype.apply = function(compiler) {
20
- function setTypeof(expr, value) {
21
- compiler.parser.plugin("evaluate typeof " + expr, function(expr) {
22
- return new BasicEvaluatedExpression().setString(value).setRange(expr.range);
23
- });
24
- compiler.parser.plugin("typeof " + expr, function(expr) {
25
- var dep = new ConstDependency(JSON.stringify(value), expr.range);
26
- dep.loc = expr.loc;
27
- this.state.current.addDependency(dep);
28
- return true;
29
- });
30
- }
31
-
32
- function setNotSupported(expr) {
33
- compiler.parser.plugin("expression " + expr, function(expr) {
34
- var dep = new ConstDependency("(void 0)", expr.range);
35
- dep.loc = expr.loc;
36
- this.state.current.addDependency(dep);
37
- if(!this.state.module) return;
38
- this.state.module.warnings.push(new UnsupportedFeatureWarning(this.state.module, expr + " is not supported by webpack."));
39
- return true;
40
- });
41
- }
20
+ var options = this.options;
42
21
  compiler.plugin("compilation", function(compilation, params) {
43
22
  var normalModuleFactory = params.normalModuleFactory;
44
23
  var contextModuleFactory = params.contextModuleFactory;
@@ -48,12 +27,52 @@ SystemPlugin.prototype.apply = function(compiler) {
48
27
 
49
28
  compilation.dependencyFactories.set(SystemImportContextDependency, contextModuleFactory);
50
29
  compilation.dependencyTemplates.set(SystemImportContextDependency, new SystemImportContextDependency.Template());
30
+
31
+ params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
32
+
33
+ if(typeof parserOptions.system !== "undefined" && !parserOptions.system)
34
+ return;
35
+
36
+ function setTypeof(expr, value) {
37
+ parser.plugin("evaluate typeof " + expr, function(expr) {
38
+ return new BasicEvaluatedExpression().setString(value).setRange(expr.range);
39
+ });
40
+ parser.plugin("typeof " + expr, function(expr) {
41
+ var dep = new ConstDependency(JSON.stringify(value), expr.range);
42
+ dep.loc = expr.loc;
43
+ this.state.current.addDependency(dep);
44
+ return true;
45
+ });
46
+ }
47
+
48
+ function setNotSupported(name) {
49
+ parser.plugin("evaluate typeof " + name, function(expr) {
50
+ return new BasicEvaluatedExpression().setString("undefined").setRange(expr.range);
51
+ });
52
+ parser.plugin("expression " + name, function(expr) {
53
+ var dep = new ConstDependency("(void 0)", expr.range);
54
+ dep.loc = expr.loc;
55
+ this.state.current.addDependency(dep);
56
+ if(!this.state.module) return;
57
+ this.state.module.warnings.push(new UnsupportedFeatureWarning(this.state.module, name + " is not supported by webpack."));
58
+ return true;
59
+ });
60
+ }
61
+
62
+ setTypeof("System", "object");
63
+ setTypeof("System.import", "function");
64
+ setNotSupported("System.set");
65
+ setNotSupported("System.get");
66
+ setNotSupported("System.register");
67
+ parser.plugin("expression System", function(expr) {
68
+ var dep = new ConstDependency("{}", expr.range);
69
+ dep.loc = expr.loc;
70
+ this.state.current.addDependency(dep);
71
+ return true;
72
+ });
73
+ parser.apply(
74
+ new SystemImportParserPlugin(options)
75
+ );
76
+ });
51
77
  });
52
- setTypeof("System", "object");
53
- setTypeof("System.import", "function");
54
- setNotSupported("System.set");
55
- setNotSupported("System.get");
56
- compiler.parser.apply(
57
- new SystemImportParserPlugin(this.options)
58
- );
59
78
  };
@@ -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
- /*global $hotChunkFilename$ hotAddUpdateChunk $hotMainFilename$ */
5
+ /*global installedChunks $hotChunkFilename$ hotAddUpdateChunk $hotMainFilename$ */
6
6
  module.exports = function() {
7
7
  function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
8
8
  var chunk = require("./" + $hotChunkFilename$);
@@ -18,7 +18,7 @@ module.exports = function() {
18
18
  return Promise.resolve(update);
19
19
  }
20
20
 
21
- function hotDiposeChunk(chunkId) {
21
+ function hotDisposeChunk(chunkId) {
22
22
  delete installedChunks[chunkId];
23
23
  }
24
24
  };
@@ -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
- /*global $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
5
+ /*global installedChunks $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
6
6
  module.exports = function() {
7
7
  function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
8
8
  var filename = require("path").join(__dirname, $hotChunkFilename$);
@@ -34,7 +34,7 @@ module.exports = function() {
34
34
  });
35
35
  }
36
36
 
37
- function hotDiposeChunk(chunkId) {
37
+ function hotDisposeChunk(chunkId) {
38
38
  delete installedChunks[chunkId];
39
39
  }
40
40
  };
@@ -1,71 +1,84 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
6
- var ModuleParserHelpers = require("../ModuleParserHelpers");
7
- var nodeLibsBrowser = require("node-libs-browser");
8
-
9
- function NodeSourcePlugin(options) {
10
- this.options = options;
11
- }
12
- module.exports = NodeSourcePlugin;
13
- NodeSourcePlugin.prototype.apply = function(compiler) {
14
- function getPathToModule(module, type) {
15
- if(type === true || (type === undefined && nodeLibsBrowser[module])) {
16
- if(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module '" + module + "' available");
17
- return nodeLibsBrowser[module];
18
- } else if(type === "mock") {
19
- return require.resolve("node-libs-browser/mock/" + module);
20
- } else if(type === "empty") {
21
- return require.resolve("node-libs-browser/mock/empty");
22
- } else return module;
23
- }
24
- if(this.options.process) {
25
- var processType = this.options.process;
26
- compiler.parser.plugin("expression process", function() {
27
- return ModuleParserHelpers.addParsedVariable(this, "process", "require(" + JSON.stringify(getPathToModule("process", processType)) + ")");
28
- });
29
- }
30
- if(this.options.global) {
31
- compiler.parser.plugin("expression global", function() {
32
- return ModuleParserHelpers.addParsedVariable(this, "global", "require(" + JSON.stringify(require.resolve("../../buildin/global.js")) + ")");
33
- });
34
- }
35
- if(this.options.console) {
36
- var consoleType = this.options.console;
37
- compiler.parser.plugin("expression console", function() {
38
- return ModuleParserHelpers.addParsedVariable(this, "console", "require(" + JSON.stringify(getPathToModule("console", consoleType)) + ")");
39
- });
40
- }
41
- var bufferType = this.options.Buffer;
42
- if(bufferType) {
43
- compiler.parser.plugin("expression Buffer", function() {
44
- return ModuleParserHelpers.addParsedVariable(this, "Buffer", "require(" + JSON.stringify(getPathToModule("buffer", bufferType)) + ").Buffer");
45
- });
46
- }
47
- if(this.options.setImmediate) {
48
- var setImmediateType = this.options.setImmediate;
49
- compiler.parser.plugin("expression setImmediate", function() {
50
- return ModuleParserHelpers.addParsedVariable(this, "setImmediate", "require(" + JSON.stringify(getPathToModule("timers", setImmediateType)) + ").setImmediate");
51
- });
52
- compiler.parser.plugin("expression clearImmediate", function() {
53
- return ModuleParserHelpers.addParsedVariable(this, "clearImmediate", "require(" + JSON.stringify(getPathToModule("timers", setImmediateType)) + ").clearImmediate");
54
- });
55
- }
56
- var options = this.options;
57
- compiler.plugin("after-resolvers", function(compiler) {
58
- var alias = {};
59
- Object.keys(nodeLibsBrowser).forEach(function(lib) {
60
- if(options[lib] !== false) {
61
- compiler.resolvers.normal.apply(
62
- new AliasPlugin("described-resolve", {
63
- name: lib,
64
- onlyModule: true,
65
- alias: getPathToModule(lib, options[lib])
66
- }, "resolve")
67
- );
68
- }
69
- });
70
- });
71
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
6
+ var ModuleParserHelpers = require("../ModuleParserHelpers");
7
+ var nodeLibsBrowser = require("node-libs-browser");
8
+
9
+ function NodeSourcePlugin(options) {
10
+ this.options = options;
11
+ }
12
+ module.exports = NodeSourcePlugin;
13
+ NodeSourcePlugin.prototype.apply = function(compiler) {
14
+ var options = this.options;
15
+
16
+ function getPathToModule(module, type) {
17
+ if(type === true || (type === undefined && nodeLibsBrowser[module])) {
18
+ if(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module '" + module + "' available");
19
+ return nodeLibsBrowser[module];
20
+ } else if(type === "mock") {
21
+ return require.resolve("node-libs-browser/mock/" + module);
22
+ } else if(type === "empty") {
23
+ return require.resolve("node-libs-browser/mock/empty");
24
+ } else return module;
25
+ }
26
+ compiler.plugin("compilation", function(compilation, params) {
27
+ params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
28
+
29
+ if(parserOptions.node === false)
30
+ return;
31
+
32
+ var localOptions = options;
33
+ if(parserOptions.node)
34
+ localOptions = Object.assign({}, localOptions, parserOptions.node);
35
+
36
+ if(localOptions.process) {
37
+ var processType = localOptions.process;
38
+ parser.plugin("expression process", function() {
39
+ return ModuleParserHelpers.addParsedVariable(this, "process", "require(" + JSON.stringify(getPathToModule("process", processType)) + ")");
40
+ });
41
+ }
42
+ if(localOptions.global) {
43
+ parser.plugin("expression global", function() {
44
+ return ModuleParserHelpers.addParsedVariable(this, "global", "require(" + JSON.stringify(require.resolve("../../buildin/global.js")) + ")");
45
+ });
46
+ }
47
+ if(localOptions.console) {
48
+ var consoleType = localOptions.console;
49
+ parser.plugin("expression console", function() {
50
+ return ModuleParserHelpers.addParsedVariable(this, "console", "require(" + JSON.stringify(getPathToModule("console", consoleType)) + ")");
51
+ });
52
+ }
53
+ var bufferType = localOptions.Buffer;
54
+ if(bufferType) {
55
+ parser.plugin("expression Buffer", function() {
56
+ return ModuleParserHelpers.addParsedVariable(this, "Buffer", "require(" + JSON.stringify(getPathToModule("buffer", bufferType)) + ").Buffer");
57
+ });
58
+ }
59
+ if(localOptions.setImmediate) {
60
+ var setImmediateType = localOptions.setImmediate;
61
+ parser.plugin("expression setImmediate", function() {
62
+ return ModuleParserHelpers.addParsedVariable(this, "setImmediate", "require(" + JSON.stringify(getPathToModule("timers", setImmediateType)) + ").setImmediate");
63
+ });
64
+ parser.plugin("expression clearImmediate", function() {
65
+ return ModuleParserHelpers.addParsedVariable(this, "clearImmediate", "require(" + JSON.stringify(getPathToModule("timers", setImmediateType)) + ").clearImmediate");
66
+ });
67
+ }
68
+ });
69
+ });
70
+ compiler.plugin("after-resolvers", function(compiler) {
71
+ var alias = {};
72
+ Object.keys(nodeLibsBrowser).forEach(function(lib) {
73
+ if(options[lib] !== false) {
74
+ compiler.resolvers.normal.apply(
75
+ new AliasPlugin("described-resolve", {
76
+ name: lib,
77
+ onlyModule: true,
78
+ alias: getPathToModule(lib, options[lib])
79
+ }, "resolve")
80
+ );
81
+ }
82
+ });
83
+ });
84
+ };
@@ -0,0 +1,52 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ function ChunkModuleIdRangePlugin(options) {
6
+ this.options = options;
7
+ }
8
+ module.exports = ChunkModuleIdRangePlugin;
9
+ ChunkModuleIdRangePlugin.prototype.apply = function(compiler) {
10
+ var options = this.options;
11
+ compiler.plugin("compilation", function(compilation) {
12
+ compilation.plugin("module-ids", function(modules) {
13
+ var chunk = this.chunks.filter(function(chunk) {
14
+ return chunk.name === options.name;
15
+ })[0];
16
+ if(!chunk) throw new Error("ChunkModuleIdRangePlugin: Chunk with name '" + options.name + "' was not found");
17
+ var currentId = options.start;
18
+ var chunkModules;
19
+ if(options.order) {
20
+ chunkModules = chunk.modules.slice();
21
+ switch(options.order) {
22
+ case "index":
23
+ chunkModules.sort(function(a, b) {
24
+ return a.index - b.index;
25
+ });
26
+ break;
27
+ case "index2":
28
+ chunkModules.sort(function(a, b) {
29
+ return a.index2 - b.index2;
30
+ });
31
+ break;
32
+ default:
33
+ throw new Error("ChunkModuleIdRangePlugin: unexpected value of order");
34
+ }
35
+
36
+ } else {
37
+ chunkModules = modules.filter(function(m) {
38
+ return m.chunks.indexOf(chunk) >= 0;
39
+ });
40
+ }
41
+ console.log(chunkModules);
42
+ for(var i = 0; i < chunkModules.length; i++) {
43
+ var m = chunkModules[i];
44
+ if(m.id === null) {
45
+ m.id = currentId++;
46
+ }
47
+ if(options.end && currentId > options.end)
48
+ break;
49
+ }
50
+ });
51
+ });
52
+ };
@@ -13,10 +13,15 @@ EnsureChunkConditionsPlugin.prototype.apply = function(compiler) {
13
13
  chunk.modules.slice().forEach(function(module) {
14
14
  if(!module.chunkCondition) return;
15
15
  if(!module.chunkCondition(chunk)) {
16
+ var usedChunks = module._EnsureChunkConditionsPlugin_usedChunks = (module._EnsureChunkConditionsPlugin_usedChunks || []).concat(chunk);
17
+ var newChunks = [];
16
18
  chunk.parents.forEach(function(parent) {
17
- parent.addModule(module);
19
+ if(usedChunks.indexOf(parent) < 0) {
20
+ parent.addModule(module);
21
+ newChunks.push(parent);
22
+ }
18
23
  });
19
- module.rewriteChunkInReasons(chunk, chunk.parents);
24
+ module.rewriteChunkInReasons(chunk, newChunks);
20
25
  chunk.removeModule(module);
21
26
  changed = true;
22
27
  }
@@ -0,0 +1,63 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Gajus Kuizinas @gajus
4
+ */
5
+ var webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
6
+ var Ajv = require("ajv");
7
+ var ajv = new Ajv({
8
+ errorDataPath: "configuration",
9
+ allErrors: true,
10
+ verbose: true
11
+ });
12
+ var validate = ajv.compile(webpackOptionsSchema);
13
+
14
+ function validateWebpackOptions(options) {
15
+ if(Array.isArray(options)) {
16
+ var errors = options.map(validateObject);
17
+ errors.forEach(function(list, idx) {
18
+ list.forEach(function applyPrefix(err) {
19
+ err.dataPath = "[" + idx + "]" + err.dataPath;
20
+ if(err.children) {
21
+ err.children.forEach(applyPrefix);
22
+ }
23
+ });
24
+ });
25
+ return errors.reduce(function(arr, items) {
26
+ return arr.concat(items);
27
+ }, []);
28
+ } else {
29
+ return validateObject(options);
30
+ }
31
+ }
32
+
33
+ function validateObject(options) {
34
+ var valid = validate(options);
35
+ return valid ? [] : filterErrors(validate.errors);
36
+ }
37
+
38
+ function filterErrors(errors) {
39
+ var errorsByDataPath = {};
40
+ var newErrors = [];
41
+ errors.forEach(function(err) {
42
+ var dataPath = err.dataPath;
43
+ var key = "$" + dataPath;
44
+ if(errorsByDataPath[key]) {
45
+ var oldError = errorsByDataPath[key];
46
+ var idx = newErrors.indexOf(oldError);
47
+ newErrors.splice(idx, 1);
48
+ if(oldError.children) {
49
+ var children = oldError.children;
50
+ delete oldError.children;
51
+ children.push(oldError);
52
+ err.children = children;
53
+ } else {
54
+ err.children = [oldError];
55
+ }
56
+ }
57
+ errorsByDataPath[key] = err;
58
+ newErrors.push(err);
59
+ });
60
+ return newErrors;
61
+ }
62
+
63
+ module.exports = validateWebpackOptions;
package/lib/webpack.js CHANGED
@@ -7,17 +7,20 @@ var MultiCompiler = require("./MultiCompiler");
7
7
  var NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
8
8
  var WebpackOptionsApply = require("./WebpackOptionsApply");
9
9
  var WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
10
+ var validateWebpackOptions = require("./validateWebpackOptions");
11
+ var WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
10
12
 
11
13
  function webpack(options, callback) {
14
+ var webpackOptionsValidationErrors = validateWebpackOptions(options);
15
+ if(webpackOptionsValidationErrors.length) {
16
+ throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
17
+ }
12
18
  var compiler;
13
19
  if(Array.isArray(options)) {
14
20
  compiler = new MultiCompiler(options.map(function(options) {
15
21
  return webpack(options);
16
22
  }));
17
23
  } else if(typeof options === "object") {
18
- if(!options.entry && !options.plugins) {
19
- throw new Error("Passed 'options' object does not look like a valid webpack configuration");
20
- }
21
24
  new WebpackOptionsDefaulter().process(options);
22
25
 
23
26
  compiler = new Compiler();
@@ -49,6 +52,7 @@ webpack.WebpackOptionsApply = WebpackOptionsApply;
49
52
  webpack.Compiler = Compiler;
50
53
  webpack.MultiCompiler = MultiCompiler;
51
54
  webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin;
55
+ webpack.validate = validateWebpackOptions;
52
56
 
53
57
  function exportPlugins(exports, path, plugins) {
54
58
  plugins.forEach(function(name) {
@@ -100,12 +104,11 @@ exportPlugins(exports.optimize = {}, "./optimize", [
100
104
  "AggressiveMergingPlugin",
101
105
  "AggressiveSplittingPlugin",
102
106
  "CommonsChunkPlugin",
107
+ "ChunkModuleIdRangePlugin",
103
108
  "DedupePlugin",
104
109
  "LimitChunkCountPlugin",
105
110
  "MinChunkSizePlugin",
106
111
  "OccurrenceOrderPlugin",
107
112
  "UglifyJsPlugin"
108
113
  ]);
109
- exportPlugins(exports.dependencies = {}, "./dependencies", [
110
- "LabeledModulesPlugin"
111
- ]);
114
+ exportPlugins(exports.dependencies = {}, "./dependencies", []);