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.
- package/bin/config-yargs.js +6 -5
- package/bin/convert-argv.js +59 -31
- package/bin/webpack.js +30 -2
- package/lib/APIPlugin.js +19 -16
- package/lib/Chunk.js +1 -1
- package/lib/CommonJsHarmonyMainTemplatePlugin.js +21 -0
- package/lib/CompatibilityPlugin.js +24 -17
- package/lib/Compilation.js +36 -15
- package/lib/Compiler.js +48 -15
- package/lib/ConstPlugin.js +40 -37
- package/lib/DefinePlugin.js +107 -103
- package/lib/DelegatedModule.js +1 -2
- package/lib/Dependency.js +5 -0
- package/lib/DllReferencePlugin.js +41 -15
- package/lib/ExtendedAPIPlugin.js +14 -11
- package/lib/FlagDependencyExportsPlugin.js +102 -0
- package/lib/FlagInitialModulesAsUsedPlugin.js +23 -23
- package/lib/FunctionModuleTemplatePlugin.js +4 -0
- package/lib/HotModuleReplacement.runtime.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +71 -68
- package/lib/LibManifestPlugin.js +1 -2
- package/lib/LibraryTemplatePlugin.js +4 -0
- package/lib/MainTemplate.js +12 -13
- package/lib/Module.js +10 -1
- package/lib/MovedToPluginWarningPlugin.js +3 -1
- package/lib/MultiCompiler.js +81 -7
- package/lib/NodeStuffPlugin.js +97 -86
- package/lib/NormalModule.js +6 -0
- package/lib/NormalModuleFactory.js +87 -34
- package/lib/Parser.js +13 -4
- package/lib/ProvidePlugin.js +30 -27
- package/lib/RequireJsStuffPlugin.js +27 -21
- package/lib/RuleSet.js +369 -0
- package/lib/Stats.js +74 -90
- package/lib/UseStrictPlugin.js +12 -8
- package/lib/WebpackOptionsApply.js +3 -13
- package/lib/WebpackOptionsDefaulter.js +0 -1
- package/lib/WebpackOptionsValidationError.js +186 -0
- package/lib/dependencies/AMDPlugin.js +64 -55
- package/lib/dependencies/CommonJsPlugin.js +55 -45
- package/lib/dependencies/HarmonyExportExpressionDependency.js +6 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +76 -16
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -4
- package/lib/dependencies/HarmonyModulesHelpers.js +0 -29
- package/lib/dependencies/HarmonyModulesPlugin.js +11 -4
- package/lib/dependencies/RequireContextPlugin.js +12 -5
- package/lib/dependencies/RequireEnsurePlugin.js +17 -10
- package/lib/dependencies/RequireIncludePlugin.js +18 -10
- package/lib/dependencies/SystemPlugin.js +48 -29
- package/lib/node/NodeMainTemplate.runtime.js +2 -2
- package/lib/node/NodeMainTemplateAsync.runtime.js +2 -2
- package/lib/node/NodeSourcePlugin.js +84 -71
- package/lib/optimize/ChunkModuleIdRangePlugin.js +52 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +7 -2
- package/lib/validateWebpackOptions.js +63 -0
- package/lib/webpack.js +9 -6
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +35 -33
- package/package.json +13 -8
- package/schemas/webpackOptionsSchema.json +802 -0
- package/README.md +0 -315
- package/lib/LoadersList.js +0 -110
- package/lib/dependencies/LabeledExportsDependency.js +0 -21
- package/lib/dependencies/LabeledModuleDependency.js +0 -36
- package/lib/dependencies/LabeledModuleDependencyParserPlugin.js +0 -78
- package/lib/dependencies/LabeledModulesPlugin.js +0 -26
package/bin/config-yargs.js
CHANGED
@@ -22,6 +22,12 @@ module.exports = function(yargs) {
|
|
22
22
|
describe: "Enviroment passed to the config, when it is a function",
|
23
23
|
group: CONFIG_GROUP
|
24
24
|
},
|
25
|
+
"version": {
|
26
|
+
type: "string",
|
27
|
+
describe: "Webpack version",
|
28
|
+
alias: "v",
|
29
|
+
group: BASIC_GROUP,
|
30
|
+
},
|
25
31
|
"context": {
|
26
32
|
type: "string",
|
27
33
|
describe: "The root directory for resolving entry point and stats",
|
@@ -184,11 +190,6 @@ module.exports = function(yargs) {
|
|
184
190
|
group: BASIC_GROUP,
|
185
191
|
requiresArg: true
|
186
192
|
},
|
187
|
-
"progress": {
|
188
|
-
type: "boolean",
|
189
|
-
describe: "Print compilation progress in percentage",
|
190
|
-
group: BASIC_GROUP
|
191
|
-
},
|
192
193
|
"resolve-alias": {
|
193
194
|
type: "string",
|
194
195
|
describe: "Setup a module alias for resolving (Example: jquery-plugin=jquery.plugin)",
|
package/bin/convert-argv.js
CHANGED
@@ -4,15 +4,22 @@ fs.existsSync = fs.existsSync || path.existsSync;
|
|
4
4
|
var resolve = require("enhanced-resolve");
|
5
5
|
var interpret = require("interpret");
|
6
6
|
var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
|
7
|
+
var validateWebpackOptions = require("../lib/validateWebpackOptions");
|
7
8
|
|
8
9
|
module.exports = function(optimist, argv, convertOptions) {
|
9
10
|
|
10
|
-
var options =
|
11
|
+
var options = [];
|
11
12
|
|
12
13
|
// Help
|
13
14
|
if(argv.help) {
|
14
15
|
optimist.showHelp();
|
15
|
-
process.exit(
|
16
|
+
process.exit(0); // eslint-disable-line
|
17
|
+
}
|
18
|
+
|
19
|
+
// Version
|
20
|
+
if(argv.v || argv.version) {
|
21
|
+
console.log(require("../package.json").version);
|
22
|
+
process.exit(0); // eslint-disable-line
|
16
23
|
}
|
17
24
|
|
18
25
|
// Shortcuts
|
@@ -29,11 +36,11 @@ module.exports = function(optimist, argv, convertOptions) {
|
|
29
36
|
}
|
30
37
|
|
31
38
|
var configFileLoaded = false;
|
32
|
-
var
|
39
|
+
var configFiles = [];
|
33
40
|
var extensions = Object.keys(interpret.extensions).sort(function(a, b) {
|
34
41
|
return a === '.js' ? -1 : b === '.js' ? 1 : a.length - b.length;
|
35
42
|
});
|
36
|
-
var
|
43
|
+
var defaultConfigFiles = ["webpack.config", "webpackfile"].map(function(filename) {
|
37
44
|
return extensions.map(function(ext) {
|
38
45
|
return {
|
39
46
|
path: path.resolve(filename + ext),
|
@@ -46,30 +53,41 @@ module.exports = function(optimist, argv, convertOptions) {
|
|
46
53
|
|
47
54
|
var i;
|
48
55
|
if(argv.config) {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
function getConfigExtension(configPath) {
|
57
|
+
for(i = extensions.length - 1; i >= 0; i--) {
|
58
|
+
var tmpExt = extensions[i];
|
59
|
+
if(configPath.indexOf(tmpExt, configPath.length - tmpExt.length) > -1) {
|
60
|
+
return tmpExt;
|
61
|
+
}
|
55
62
|
}
|
63
|
+
return path.extname(configPath);
|
56
64
|
}
|
57
|
-
|
58
|
-
|
65
|
+
|
66
|
+
function mapConfigArg(configArg) {
|
67
|
+
var resolvedPath = path.resolve(configArg);
|
68
|
+
var extension = getConfigExtension(resolvedPath);
|
69
|
+
return {
|
70
|
+
path: resolvedPath,
|
71
|
+
ext: extension
|
72
|
+
};
|
59
73
|
}
|
74
|
+
|
75
|
+
var configArgList = Array.isArray(argv.config) ? argv.config : [argv.config];
|
76
|
+
configFiles = configArgList.map(mapConfigArg);
|
60
77
|
} else {
|
61
|
-
for(i = 0; i <
|
62
|
-
var webpackConfig =
|
78
|
+
for(i = 0; i < defaultConfigFiles.length; i++) {
|
79
|
+
var webpackConfig = defaultConfigFiles[i].path;
|
63
80
|
if(fs.existsSync(webpackConfig)) {
|
64
|
-
|
65
|
-
|
81
|
+
configFiles.push({
|
82
|
+
path: webpackConfig,
|
83
|
+
ext: defaultConfigFiles[i].ext
|
84
|
+
});
|
66
85
|
break;
|
67
86
|
}
|
68
87
|
}
|
69
88
|
}
|
70
89
|
|
71
|
-
if(
|
72
|
-
|
90
|
+
if(configFiles.length > 0) {
|
73
91
|
function registerCompiler(moduleDescriptor) {
|
74
92
|
if(moduleDescriptor) {
|
75
93
|
if(typeof moduleDescriptor === "string") {
|
@@ -89,22 +107,33 @@ module.exports = function(optimist, argv, convertOptions) {
|
|
89
107
|
}
|
90
108
|
}
|
91
109
|
|
92
|
-
|
93
|
-
|
110
|
+
function requireConfig(configPath) {
|
111
|
+
var options = require(configPath);
|
112
|
+
var isES6DefaultExportedFunc = (
|
113
|
+
typeof options === "object" && options !== null && typeof options.default === "function"
|
114
|
+
);
|
115
|
+
if(typeof options === "function" || isES6DefaultExportedFunc) {
|
116
|
+
options = isES6DefaultExportedFunc ? options.default : options;
|
117
|
+
options = options(argv.env, argv);
|
118
|
+
}
|
119
|
+
return options;
|
120
|
+
}
|
121
|
+
|
122
|
+
configFiles.forEach(function(file) {
|
123
|
+
registerCompiler(interpret.extensions[file.ext]);
|
124
|
+
options.push(requireConfig(file.path));
|
125
|
+
});
|
94
126
|
configFileLoaded = true;
|
95
127
|
}
|
96
128
|
|
97
|
-
|
98
|
-
|
99
|
-
)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
options = options(argv.env, argv);
|
129
|
+
if(!configFileLoaded) {
|
130
|
+
return processConfiguredOptions({});
|
131
|
+
} else if(options.length === 1) {
|
132
|
+
return processConfiguredOptions(options[0]);
|
133
|
+
} else {
|
134
|
+
return processConfiguredOptions(options);
|
104
135
|
}
|
105
136
|
|
106
|
-
return processConfiguredOptions(options);
|
107
|
-
|
108
137
|
function processConfiguredOptions(options) {
|
109
138
|
if(options === null || typeof options !== "object") {
|
110
139
|
console.error("Config did not export an object or a function returning an object.");
|
@@ -162,7 +191,6 @@ module.exports = function(optimist, argv, convertOptions) {
|
|
162
191
|
|
163
192
|
function processOptions(options) {
|
164
193
|
var noOutputFilenameDefined = !options.output || !options.output.filename;
|
165
|
-
new WebpackOptionsDefaulter().process(options);
|
166
194
|
|
167
195
|
function ifArg(name, fn, init, finalize) {
|
168
196
|
if(Array.isArray(argv[name])) {
|
@@ -537,7 +565,7 @@ module.exports = function(optimist, argv, convertOptions) {
|
|
537
565
|
}
|
538
566
|
|
539
567
|
if(!options.entry) {
|
540
|
-
if(
|
568
|
+
if(configFileLoaded) {
|
541
569
|
console.error("Configuration file found but no entry configured.");
|
542
570
|
} else {
|
543
571
|
console.error("No configuration file found and no entry configured via CLI option.");
|
package/bin/webpack.js
CHANGED
@@ -21,6 +21,7 @@ var yargs = require("yargs")
|
|
21
21
|
require("./config-yargs")(yargs);
|
22
22
|
|
23
23
|
var DISPLAY_GROUP = "Stats options:";
|
24
|
+
var BASIC_GROUP = "Basic options:";
|
24
25
|
|
25
26
|
yargs.options({
|
26
27
|
"json": {
|
@@ -28,6 +29,11 @@ yargs.options({
|
|
28
29
|
alias: "j",
|
29
30
|
describe: "Prints the result as JSON."
|
30
31
|
},
|
32
|
+
"progress": {
|
33
|
+
type: "boolean",
|
34
|
+
describe: "Print compilation progress in percentage",
|
35
|
+
group: BASIC_GROUP
|
36
|
+
},
|
31
37
|
"color": {
|
32
38
|
type: "boolean",
|
33
39
|
alias: "colors",
|
@@ -102,6 +108,11 @@ yargs.options({
|
|
102
108
|
group: DISPLAY_GROUP,
|
103
109
|
describe: "Display information about used exports in modules (Tree Shaking)"
|
104
110
|
},
|
111
|
+
"display-provided-exports": {
|
112
|
+
type: "boolean",
|
113
|
+
group: DISPLAY_GROUP,
|
114
|
+
describe: "Display information about exports provided from modules"
|
115
|
+
},
|
105
116
|
"display-error-details": {
|
106
117
|
type: "boolean",
|
107
118
|
group: DISPLAY_GROUP,
|
@@ -110,7 +121,6 @@ yargs.options({
|
|
110
121
|
"verbose": {
|
111
122
|
type: "boolean",
|
112
123
|
group: DISPLAY_GROUP,
|
113
|
-
alias: "v",
|
114
124
|
describe: "Show more details"
|
115
125
|
}
|
116
126
|
});
|
@@ -121,6 +131,7 @@ if(argv.verbose) {
|
|
121
131
|
argv["display-reasons"] = true;
|
122
132
|
argv["display-entrypoints"] = true;
|
123
133
|
argv["display-used-exports"] = true;
|
134
|
+
argv["display-provided-exports"] = true;
|
124
135
|
argv["display-error-details"] = true;
|
125
136
|
argv["display-modules"] = true;
|
126
137
|
argv["display-cached"] = true;
|
@@ -207,6 +218,10 @@ function processOptions(options) {
|
|
207
218
|
outputOptions.usedExports = bool;
|
208
219
|
});
|
209
220
|
|
221
|
+
ifArg("display-provided-exports", function(bool) {
|
222
|
+
outputOptions.providedExports = bool;
|
223
|
+
});
|
224
|
+
|
210
225
|
ifArg("display-error-details", function(bool) {
|
211
226
|
outputOptions.errorDetails = bool;
|
212
227
|
});
|
@@ -255,7 +270,20 @@ function processOptions(options) {
|
|
255
270
|
|
256
271
|
Error.stackTraceLimit = 30;
|
257
272
|
var lastHash = null;
|
258
|
-
var compiler
|
273
|
+
var compiler;
|
274
|
+
try {
|
275
|
+
compiler = webpack(options);
|
276
|
+
} catch(e) {
|
277
|
+
var WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError");
|
278
|
+
if(e instanceof WebpackOptionsValidationError) {
|
279
|
+
if(argv.color)
|
280
|
+
console.error("\u001b[1m\u001b[31m" + e.message + "\u001b[39m\u001b[22m");
|
281
|
+
else
|
282
|
+
console.error(e.message);
|
283
|
+
process.exit(1);
|
284
|
+
}
|
285
|
+
throw e;
|
286
|
+
}
|
259
287
|
|
260
288
|
if(argv.progress) {
|
261
289
|
var ProgressPlugin = require("../lib/ProgressPlugin");
|
package/lib/APIPlugin.js
CHANGED
@@ -26,24 +26,27 @@ var REPLACEMENT_TYPES = {
|
|
26
26
|
};
|
27
27
|
var IGNORES = [];
|
28
28
|
APIPlugin.prototype.apply = function(compiler) {
|
29
|
-
compiler.plugin("compilation", function(compilation) {
|
29
|
+
compiler.plugin("compilation", function(compilation, params) {
|
30
30
|
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
31
31
|
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
|
33
|
+
params.normalModuleFactory.plugin("parser", function(parser) {
|
34
|
+
Object.keys(REPLACEMENTS).forEach(function(key) {
|
35
|
+
parser.plugin("expression " + key, function(expr) {
|
36
|
+
var dep = new ConstDependency(REPLACEMENTS[key], expr.range);
|
37
|
+
dep.loc = expr.loc;
|
38
|
+
this.state.current.addDependency(dep);
|
39
|
+
return true;
|
40
|
+
});
|
41
|
+
parser.plugin("evaluate typeof " + key, function(expr) {
|
42
|
+
return new BasicEvaluatedExpression().setString(REPLACEMENT_TYPES[key]).setRange(expr.range);
|
43
|
+
});
|
44
|
+
});
|
45
|
+
IGNORES.forEach(function(key) {
|
46
|
+
parser.plugin(key, function() {
|
47
|
+
return true;
|
48
|
+
});
|
49
|
+
});
|
47
50
|
});
|
48
51
|
});
|
49
52
|
};
|
package/lib/Chunk.js
CHANGED
@@ -279,7 +279,7 @@ Chunk.prototype.integratedSize = function(other, options) {
|
|
279
279
|
return false;
|
280
280
|
}
|
281
281
|
|
282
|
-
var CHUNK_OVERHEAD = options.chunkOverhead
|
282
|
+
var CHUNK_OVERHEAD = typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
|
283
283
|
var ENTRY_CHUNK_MULTIPLICATOR = options.entryChunkMultiplicator || 10;
|
284
284
|
|
285
285
|
var mergedModules = this.modules.slice();
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
var ConcatSource = require("webpack-sources").ConcatSource;
|
6
|
+
|
7
|
+
function CommonJsHarmonyMainTemplatePlugin() {}
|
8
|
+
|
9
|
+
module.exports = CommonJsHarmonyMainTemplatePlugin;
|
10
|
+
|
11
|
+
CommonJsHarmonyMainTemplatePlugin.prototype.apply = function(compilation) {
|
12
|
+
var mainTemplate = compilation.mainTemplate;
|
13
|
+
compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) {
|
14
|
+
var prefix = "module.exports =\n";
|
15
|
+
var postfix = "\nObject.defineProperty(module.exports, \"__esModule\", { value: true });";
|
16
|
+
return new ConcatSource(prefix, source, postfix);
|
17
|
+
});
|
18
|
+
mainTemplate.plugin("hash", function(hash) {
|
19
|
+
hash.update("commonjs harmony");
|
20
|
+
});
|
21
|
+
};
|
@@ -11,24 +11,31 @@ function CompatibilityPlugin() {}
|
|
11
11
|
module.exports = CompatibilityPlugin;
|
12
12
|
|
13
13
|
CompatibilityPlugin.prototype.apply = function(compiler) {
|
14
|
-
compiler.plugin("compilation", function(compilation) {
|
14
|
+
compiler.plugin("compilation", function(compilation, params) {
|
15
15
|
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
16
16
|
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
17
|
+
|
18
|
+
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
|
19
|
+
|
20
|
+
if(typeof parserOptions.browserify !== "undefined" && !parserOptions.browserify)
|
21
|
+
return;
|
22
|
+
|
23
|
+
parser.plugin("call require", function(expr) {
|
24
|
+
// support for browserify style require delegator: "require(o, !0)"
|
25
|
+
if(expr.arguments.length !== 2) return;
|
26
|
+
var second = this.evaluateExpression(expr.arguments[1]);
|
27
|
+
if(!second.isBoolean()) return;
|
28
|
+
if(second.asBool() !== true) return;
|
29
|
+
var dep = new ConstDependency("require", expr.callee.range);
|
30
|
+
dep.loc = expr.loc;
|
31
|
+
if(this.state.current.dependencies.length > 1) {
|
32
|
+
var last = this.state.current.dependencies[this.state.current.dependencies.length - 1];
|
33
|
+
if(last.critical && last.request === "." && last.userRequest === "." && last.recursive)
|
34
|
+
this.state.current.dependencies.pop();
|
35
|
+
}
|
36
|
+
this.state.current.addDependency(dep);
|
37
|
+
return true;
|
38
|
+
});
|
39
|
+
});
|
33
40
|
});
|
34
41
|
};
|
package/lib/Compilation.js
CHANGED
@@ -209,6 +209,9 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
|
|
209
209
|
|
210
210
|
var factory = item[0];
|
211
211
|
factory.create({
|
212
|
+
contextInfo: {
|
213
|
+
issuer: module.nameForCondition && module.nameForCondition()
|
214
|
+
},
|
212
215
|
context: module.context,
|
213
216
|
dependencies: dependencies
|
214
217
|
}, function(err, dependentModule) {
|
@@ -424,6 +427,11 @@ Compilation.prototype._addModuleChain = function process(context, dependency, on
|
|
424
427
|
};
|
425
428
|
|
426
429
|
Compilation.prototype.addEntry = function process(context, entry, name, callback) {
|
430
|
+
var slot = {
|
431
|
+
name: name,
|
432
|
+
module: null
|
433
|
+
};
|
434
|
+
this.preparedChunks.push(slot);
|
427
435
|
this._addModuleChain(context, entry, function(module) {
|
428
436
|
|
429
437
|
entry.module = module;
|
@@ -436,10 +444,10 @@ Compilation.prototype.addEntry = function process(context, entry, name, callback
|
|
436
444
|
}
|
437
445
|
|
438
446
|
if(module) {
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
447
|
+
slot.module = module;
|
448
|
+
} else {
|
449
|
+
var idx = this.preparedChunks.indexOf(slot);
|
450
|
+
this.preparedChunks.splice(idx, 1);
|
443
451
|
}
|
444
452
|
return callback();
|
445
453
|
}.bind(this));
|
@@ -511,11 +519,6 @@ Compilation.prototype.unseal = function unseal() {
|
|
511
519
|
|
512
520
|
Compilation.prototype.seal = function seal(callback) {
|
513
521
|
this.applyPlugins("seal");
|
514
|
-
this.preparedChunks.sort(function(a, b) {
|
515
|
-
if(a.name < b.name) return -1;
|
516
|
-
if(a.name > b.name) return 1;
|
517
|
-
return 0;
|
518
|
-
});
|
519
522
|
this.nextFreeModuleIndex = 0;
|
520
523
|
this.nextFreeModuleIndex2 = 0;
|
521
524
|
this.preparedChunks.forEach(function(preparedChunk) {
|
@@ -561,7 +564,9 @@ Compilation.prototype.seal = function seal(callback) {
|
|
561
564
|
|
562
565
|
this.applyPlugins("revive-modules", this.modules, this.records);
|
563
566
|
this.applyPlugins("optimize-module-order", this.modules);
|
567
|
+
this.applyPlugins("advanced-optimize-module-order", this.modules);
|
564
568
|
this.applyPlugins("before-module-ids", this.modules);
|
569
|
+
this.applyPlugins("module-ids", this.modules);
|
565
570
|
this.applyModuleIds();
|
566
571
|
this.applyPlugins("optimize-module-ids", this.modules);
|
567
572
|
this.applyPlugins("after-optimize-module-ids", this.modules);
|
@@ -742,10 +747,24 @@ Compilation.prototype.removeChunkFromDependencies = function removeChunkFromDepe
|
|
742
747
|
Compilation.prototype.applyModuleIds = function applyModuleIds() {
|
743
748
|
var unusedIds = [];
|
744
749
|
var nextFreeModuleId = 0;
|
750
|
+
var usedIds = [];
|
751
|
+
var usedIdMap = {};
|
745
752
|
if(this.usedModuleIds) {
|
746
|
-
|
747
|
-
|
748
|
-
|
753
|
+
Object.keys(this.usedModuleIds).forEach(function(key) {
|
754
|
+
var id = this.usedModuleIds[key];
|
755
|
+
if(typeof usedIdMap[id] === "undefined") {
|
756
|
+
usedIds.push(id);
|
757
|
+
usedIdMap[id] = id;
|
758
|
+
}
|
759
|
+
}, this);
|
760
|
+
}
|
761
|
+
this.modules.forEach(function(module) {
|
762
|
+
if(module.id !== null && typeof usedIdMap[module.id] === "undefined") {
|
763
|
+
usedIds.push(module.id);
|
764
|
+
usedIdMap[module.id] = module.id;
|
765
|
+
}
|
766
|
+
});
|
767
|
+
if(usedIds.length > 0) {
|
749
768
|
var usedNumberIds = usedIds.filter(function(id) {
|
750
769
|
return typeof id === "number";
|
751
770
|
});
|
@@ -753,7 +772,7 @@ Compilation.prototype.applyModuleIds = function applyModuleIds() {
|
|
753
772
|
return Math.max(a, b);
|
754
773
|
}, -1) + 1;
|
755
774
|
for(var i = 0; i < nextFreeModuleId; i++) {
|
756
|
-
if(
|
775
|
+
if(usedIdMap[i] !== i)
|
757
776
|
unusedIds.push(i);
|
758
777
|
}
|
759
778
|
unusedIds.reverse();
|
@@ -801,7 +820,9 @@ Compilation.prototype.applyChunkIds = function applyChunkIds() {
|
|
801
820
|
};
|
802
821
|
|
803
822
|
function byId(a, b) {
|
804
|
-
|
823
|
+
if(a.id < b.id) return -1;
|
824
|
+
if(a.id > b.id) return 1;
|
825
|
+
return 0;
|
805
826
|
}
|
806
827
|
|
807
828
|
Compilation.prototype.sortItemsBeforeIds = function sortItemsBeforeIds() {
|
@@ -834,7 +855,7 @@ Compilation.prototype.summarizeDependencies = function summarizeDependencies() {
|
|
834
855
|
}
|
835
856
|
return newArray;
|
836
857
|
}
|
837
|
-
this.fileDependencies = [];
|
858
|
+
this.fileDependencies = (this.compilationDependencies || []).slice();
|
838
859
|
this.contextDependencies = [];
|
839
860
|
this.missingDependencies = [];
|
840
861
|
this.children.forEach(function(child) {
|
package/lib/Compiler.js
CHANGED
@@ -7,7 +7,6 @@ var assign = require("object-assign");
|
|
7
7
|
var Tapable = require("tapable");
|
8
8
|
|
9
9
|
var Compilation = require("./Compilation");
|
10
|
-
var Parser = require("./Parser");
|
11
10
|
var Resolver = require("enhanced-resolve/lib/Resolver");
|
12
11
|
|
13
12
|
var NormalModuleFactory = require("./NormalModuleFactory");
|
@@ -160,7 +159,36 @@ function Compiler() {
|
|
160
159
|
loader: new Resolver(null),
|
161
160
|
context: new Resolver(null)
|
162
161
|
};
|
163
|
-
|
162
|
+
var deprecationReported = false;
|
163
|
+
this.parser = {
|
164
|
+
plugin: function(hook, fn) {
|
165
|
+
if(!deprecationReported) {
|
166
|
+
console.warn("webpack: Using compiler.parser is deprecated.\n" +
|
167
|
+
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. " +
|
168
|
+
"It was called " + new Error().stack.split("\n")[2].trim() + ".");
|
169
|
+
deprecationReported = true;
|
170
|
+
}
|
171
|
+
this.plugin("compilation", function(compilation, data) {
|
172
|
+
data.normalModuleFactory.plugin("parser", function(parser) {
|
173
|
+
parser.plugin(hook, fn);
|
174
|
+
});
|
175
|
+
});
|
176
|
+
}.bind(this),
|
177
|
+
apply: function() {
|
178
|
+
var args = arguments;
|
179
|
+
if(!deprecationReported) {
|
180
|
+
console.warn("webpack: Using compiler.parser is deprecated.\n" +
|
181
|
+
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. " +
|
182
|
+
"It was called " + new Error().stack.split("\n")[2].trim() + ".");
|
183
|
+
deprecationReported = true;
|
184
|
+
}
|
185
|
+
this.plugin("compilation", function(compilation, data) {
|
186
|
+
data.normalModuleFactory.plugin("parser", function(parser) {
|
187
|
+
parser.apply.apply(parser, args);
|
188
|
+
});
|
189
|
+
});
|
190
|
+
}.bind(this)
|
191
|
+
}
|
164
192
|
|
165
193
|
this.options = {};
|
166
194
|
}
|
@@ -369,7 +397,6 @@ Compiler.prototype.createChildCompiler = function(compilation, compilerName, out
|
|
369
397
|
childCompiler.inputFileSystem = this.inputFileSystem;
|
370
398
|
childCompiler.outputFileSystem = null;
|
371
399
|
childCompiler.resolvers = this.resolvers;
|
372
|
-
childCompiler.parser = this.parser;
|
373
400
|
childCompiler.fileTimestamps = this.fileTimestamps;
|
374
401
|
childCompiler.contextTimestamps = this.contextTimestamps;
|
375
402
|
if(!this.records[compilerName]) this.records[compilerName] = [];
|
@@ -397,13 +424,14 @@ Compiler.prototype.newCompilation = function(params) {
|
|
397
424
|
compilation.contextTimestamps = this.contextTimestamps;
|
398
425
|
compilation.name = this.name;
|
399
426
|
compilation.records = this.records;
|
427
|
+
compilation.compilationDependencies = params.compilationDependencies;
|
400
428
|
this.applyPlugins("this-compilation", compilation, params);
|
401
429
|
this.applyPlugins("compilation", compilation, params);
|
402
430
|
return compilation;
|
403
431
|
};
|
404
432
|
|
405
433
|
Compiler.prototype.createNormalModuleFactory = function() {
|
406
|
-
var normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolvers, this.
|
434
|
+
var normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolvers, this.options.module || {});
|
407
435
|
this.applyPlugins("normal-module-factory", normalModuleFactory);
|
408
436
|
return normalModuleFactory;
|
409
437
|
};
|
@@ -417,30 +445,35 @@ Compiler.prototype.createContextModuleFactory = function() {
|
|
417
445
|
Compiler.prototype.newCompilationParams = function() {
|
418
446
|
var params = {
|
419
447
|
normalModuleFactory: this.createNormalModuleFactory(),
|
420
|
-
contextModuleFactory: this.createContextModuleFactory()
|
448
|
+
contextModuleFactory: this.createContextModuleFactory(),
|
449
|
+
compilationDependencies: []
|
421
450
|
};
|
422
451
|
return params;
|
423
452
|
};
|
424
453
|
|
425
454
|
Compiler.prototype.compile = function(callback) {
|
426
455
|
var params = this.newCompilationParams();
|
427
|
-
this.
|
428
|
-
|
429
|
-
var compilation = this.newCompilation(params);
|
430
|
-
|
431
|
-
this.applyPluginsParallel("make", compilation, function(err) {
|
456
|
+
this.applyPluginsAsync("before-compile", params, function(err) {
|
432
457
|
if(err) return callback(err);
|
433
458
|
|
434
|
-
|
459
|
+
this.applyPlugins("compile", params);
|
435
460
|
|
436
|
-
compilation.
|
461
|
+
var compilation = this.newCompilation(params);
|
462
|
+
|
463
|
+
this.applyPluginsParallel("make", compilation, function(err) {
|
437
464
|
if(err) return callback(err);
|
438
465
|
|
439
|
-
|
466
|
+
compilation.finish();
|
467
|
+
|
468
|
+
compilation.seal(function(err) {
|
440
469
|
if(err) return callback(err);
|
441
470
|
|
442
|
-
|
443
|
-
|
471
|
+
this.applyPluginsAsync("after-compile", compilation, function(err) {
|
472
|
+
if(err) return callback(err);
|
473
|
+
|
474
|
+
return callback(null, compilation);
|
475
|
+
});
|
476
|
+
}.bind(this));
|
444
477
|
}.bind(this));
|
445
478
|
}.bind(this));
|
446
479
|
};
|