webpack 2.2.0 → 2.2.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.
- package/README.md +39 -63
- package/lib/APIPlugin.js +2 -8
- package/lib/AsyncDependenciesBlock.js +46 -55
- package/lib/ChunkTemplate.js +25 -26
- package/lib/CompatibilityPlugin.js +49 -46
- package/lib/Compilation.js +279 -138
- package/lib/ConstPlugin.js +2 -6
- package/lib/DefinePlugin.js +9 -27
- package/lib/EnvironmentPlugin.js +25 -9
- package/lib/EvalDevToolModulePlugin.js +15 -10
- package/lib/EvalSourceMapDevToolPlugin.js +24 -18
- package/lib/ExtendedAPIPlugin.js +1 -6
- package/lib/FlagDependencyExportsPlugin.js +72 -79
- package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
- package/lib/FunctionModulePlugin.js +17 -11
- package/lib/HotModuleReplacementPlugin.js +3 -13
- package/lib/HotUpdateChunkTemplate.js +21 -22
- package/lib/JsonpTemplatePlugin.js +15 -11
- package/lib/LoaderTargetPlugin.js +14 -10
- package/lib/MainTemplate.js +193 -191
- package/lib/MultiWatching.js +16 -14
- package/lib/NoEmitOnErrorsPlugin.js +14 -11
- package/lib/NodeStuffPlugin.js +6 -30
- package/lib/NormalModuleFactory.js +2 -2
- package/lib/NormalModuleReplacementPlugin.js +36 -31
- package/lib/Parser.js +8 -7
- package/lib/ParserHelpers.js +19 -5
- package/lib/ProvidePlugin.js +2 -6
- package/lib/RequestShortener.js +49 -47
- package/lib/RequireJsStuffPlugin.js +5 -20
- package/lib/RuleSet.js +28 -20
- package/lib/Template.js +133 -132
- package/lib/compareLocations.js +9 -8
- package/lib/dependencies/AMDPlugin.js +111 -115
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
- package/lib/dependencies/CommonJsPlugin.js +81 -85
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
- package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
- package/lib/dependencies/CriticalDependencyWarning.js +13 -8
- package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
- package/lib/dependencies/ImportParserPlugin.js +31 -28
- package/lib/dependencies/ImportPlugin.js +28 -24
- package/lib/dependencies/LocalModule.js +17 -13
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
- package/lib/dependencies/RequireContextPlugin.js +59 -57
- package/lib/dependencies/RequireEnsurePlugin.js +22 -26
- package/lib/dependencies/RequireIncludePlugin.js +18 -23
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
- package/lib/dependencies/SystemPlugin.js +34 -36
- package/lib/dependencies/WebpackMissingModule.js +10 -18
- package/lib/node/NodeTargetPlugin.js +8 -5
- package/lib/node/NodeWatchFileSystem.js +54 -53
- package/lib/optimize/CommonsChunkPlugin.js +163 -166
- package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
- package/lib/validateSchema.js +18 -18
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
- package/package.json +12 -6
package/lib/DefinePlugin.js
CHANGED
@@ -35,10 +35,10 @@ class DefinePlugin {
|
|
35
35
|
}(definitions, ""));
|
36
36
|
|
37
37
|
function stringifyObj(obj) {
|
38
|
-
return "{" + Object.keys(obj).map((key) => {
|
38
|
+
return "__webpack_require__.i({" + Object.keys(obj).map((key) => {
|
39
39
|
let code = obj[key];
|
40
40
|
return JSON.stringify(key) + ":" + toCode(code);
|
41
|
-
}).join(",") + "}";
|
41
|
+
}).join(",") + "})";
|
42
42
|
}
|
43
43
|
|
44
44
|
function toCode(code) {
|
@@ -54,7 +54,7 @@ class DefinePlugin {
|
|
54
54
|
const splittedKey = key.split(".");
|
55
55
|
splittedKey.slice(1).forEach((_, i) => {
|
56
56
|
const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
|
57
|
-
parser.plugin("can-rename " + fullKey,
|
57
|
+
parser.plugin("can-rename " + fullKey, ParserHelpers.approve);
|
58
58
|
});
|
59
59
|
}
|
60
60
|
|
@@ -65,7 +65,7 @@ class DefinePlugin {
|
|
65
65
|
let recurseTypeof = false;
|
66
66
|
code = toCode(code);
|
67
67
|
if(!isTypeof) {
|
68
|
-
parser.plugin("can-rename " + key,
|
68
|
+
parser.plugin("can-rename " + key, ParserHelpers.approve);
|
69
69
|
parser.plugin("evaluate Identifier " + key, (expr) => {
|
70
70
|
if(recurse) return;
|
71
71
|
let res = parser.evaluate(code);
|
@@ -73,12 +73,7 @@ class DefinePlugin {
|
|
73
73
|
res.setRange(expr.range);
|
74
74
|
return res;
|
75
75
|
});
|
76
|
-
parser.plugin("expression " + key, (
|
77
|
-
let dep = new ConstDependency(code, expr.range);
|
78
|
-
dep.loc = expr.loc;
|
79
|
-
parser.state.current.addDependency(dep);
|
80
|
-
return true;
|
81
|
-
});
|
76
|
+
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(code));
|
82
77
|
}
|
83
78
|
let typeofCode = isTypeof ? code : "typeof (" + code + ")";
|
84
79
|
parser.plugin("evaluate typeof " + key, (expr) => {
|
@@ -91,30 +86,17 @@ class DefinePlugin {
|
|
91
86
|
parser.plugin("typeof " + key, (expr) => {
|
92
87
|
let res = parser.evaluate(typeofCode);
|
93
88
|
if(!res.isString()) return;
|
94
|
-
|
95
|
-
dep.loc = expr.loc;
|
96
|
-
parser.state.current.addDependency(dep);
|
97
|
-
return true;
|
89
|
+
return ParserHelpers.toConstantDependency(JSON.stringify(res.string)).bind(parser)(expr);
|
98
90
|
});
|
99
91
|
}
|
100
92
|
|
101
93
|
function applyObjectDefine(key, obj) {
|
102
94
|
let code = stringifyObj(obj);
|
103
|
-
parser.plugin("can-rename " + key,
|
95
|
+
parser.plugin("can-rename " + key, ParserHelpers.approve);
|
104
96
|
parser.plugin("evaluate Identifier " + key, (expr) => new BasicEvaluatedExpression().setRange(expr.range));
|
105
97
|
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString("object"));
|
106
|
-
parser.plugin("expression " + key, (
|
107
|
-
|
108
|
-
dep.loc = expr.loc;
|
109
|
-
parser.state.current.addDependency(dep);
|
110
|
-
return true;
|
111
|
-
});
|
112
|
-
parser.plugin("typeof " + key, (expr) => {
|
113
|
-
let dep = new ConstDependency("\"object\"", expr.range);
|
114
|
-
dep.loc = expr.loc;
|
115
|
-
parser.state.current.addDependency(dep);
|
116
|
-
return true;
|
117
|
-
});
|
98
|
+
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(code));
|
99
|
+
parser.plugin("typeof " + key, ParserHelpers.toConstantDependency(JSON.stringify("object")));
|
118
100
|
}
|
119
101
|
});
|
120
102
|
});
|
package/lib/EnvironmentPlugin.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
|
3
|
+
Authors Simen Brekken @simenbrekken, Einar Löve @einarlove
|
4
4
|
*/
|
5
5
|
|
6
6
|
"use strict";
|
@@ -9,25 +9,41 @@ const DefinePlugin = require("./DefinePlugin");
|
|
9
9
|
|
10
10
|
class EnvironmentPlugin {
|
11
11
|
constructor(keys) {
|
12
|
-
|
12
|
+
if(Array.isArray(keys)) {
|
13
|
+
this.keys = keys;
|
14
|
+
this.defaultValues = {};
|
15
|
+
} else if(keys && typeof keys === "object") {
|
16
|
+
this.keys = Object.keys(keys);
|
17
|
+
this.defaultValues = keys;
|
18
|
+
} else {
|
19
|
+
this.keys = Array.prototype.slice.call(arguments);
|
20
|
+
this.defaultValues = {};
|
21
|
+
}
|
13
22
|
}
|
14
23
|
|
15
24
|
apply(compiler) {
|
16
|
-
|
17
|
-
const value = process.env[key];
|
25
|
+
const definitions = this.keys.reduce((defs, key) => {
|
26
|
+
const value = process.env[key] || this.defaultValues[key];
|
18
27
|
|
19
28
|
if(value === undefined) {
|
20
|
-
compiler.plugin("this-compilation",
|
21
|
-
const error = new Error(
|
29
|
+
compiler.plugin("this-compilation", compilation => {
|
30
|
+
const error = new Error(
|
31
|
+
`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
|
32
|
+
"You can pass an object with default values to suppress this warning.\n" +
|
33
|
+
"See https://webpack.js.org/plugins/environment-plugin for example."
|
34
|
+
);
|
35
|
+
|
22
36
|
error.name = "EnvVariableNotDefinedError";
|
23
37
|
compilation.warnings.push(error);
|
24
38
|
});
|
25
39
|
}
|
26
40
|
|
27
|
-
|
41
|
+
defs[`process.env.${key}`] = typeof value === "undefined" ? "undefined" : JSON.stringify(value);
|
42
|
+
|
43
|
+
return defs;
|
44
|
+
}, {});
|
28
45
|
|
29
|
-
|
30
|
-
}, {})));
|
46
|
+
compiler.apply(new DefinePlugin(definitions));
|
31
47
|
}
|
32
48
|
}
|
33
49
|
|
@@ -2,16 +2,21 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
const EvalDevToolModuleTemplatePlugin = require("./EvalDevToolModuleTemplatePlugin");
|
8
|
+
|
9
|
+
class EvalDevToolModulePlugin {
|
10
|
+
constructor(sourceUrlComment, moduleFilenameTemplate) {
|
11
|
+
this.sourceUrlComment = sourceUrlComment;
|
12
|
+
this.moduleFilenameTemplate = moduleFilenameTemplate;
|
13
|
+
}
|
14
|
+
|
15
|
+
apply(compiler) {
|
16
|
+
compiler.plugin("compilation", (compilation) => {
|
17
|
+
compilation.moduleTemplate.apply(new EvalDevToolModuleTemplatePlugin(this.sourceUrlComment, this.moduleFilenameTemplate));
|
18
|
+
});
|
19
|
+
}
|
10
20
|
}
|
21
|
+
|
11
22
|
module.exports = EvalDevToolModulePlugin;
|
12
|
-
EvalDevToolModulePlugin.prototype.apply = function(compiler) {
|
13
|
-
var self = this;
|
14
|
-
compiler.plugin("compilation", function(compilation) {
|
15
|
-
compilation.moduleTemplate.apply(new EvalDevToolModuleTemplatePlugin(self.sourceUrlComment, self.moduleFilenameTemplate));
|
16
|
-
});
|
17
|
-
};
|
@@ -2,25 +2,31 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
const EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
8
|
+
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
9
|
+
|
10
|
+
class EvalSourceMapDevToolPlugin {
|
11
|
+
constructor(options) {
|
12
|
+
if(arguments.length > 1)
|
13
|
+
throw new Error("EvalSourceMapDevToolPlugin only takes one argument (pass an options object)");
|
14
|
+
if(typeof options === "string") {
|
15
|
+
options = {
|
16
|
+
append: options
|
17
|
+
};
|
18
|
+
}
|
19
|
+
if(!options) options = {};
|
20
|
+
this.options = options;
|
21
|
+
}
|
22
|
+
|
23
|
+
apply(compiler) {
|
24
|
+
let options = this.options;
|
25
|
+
compiler.plugin("compilation", (compilation) => {
|
26
|
+
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
27
|
+
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
|
28
|
+
});
|
15
29
|
}
|
16
|
-
if(!options) options = {};
|
17
|
-
this.options = options;
|
18
30
|
}
|
31
|
+
|
19
32
|
module.exports = EvalSourceMapDevToolPlugin;
|
20
|
-
EvalSourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
21
|
-
var options = this.options;
|
22
|
-
compiler.plugin("compilation", function(compilation) {
|
23
|
-
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
24
|
-
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
|
25
|
-
});
|
26
|
-
};
|
package/lib/ExtendedAPIPlugin.js
CHANGED
@@ -34,12 +34,7 @@ ExtendedAPIPlugin.prototype.apply = function(compiler) {
|
|
34
34
|
|
35
35
|
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
|
36
36
|
Object.keys(REPLACEMENTS).forEach(function(key) {
|
37
|
-
parser.plugin("expression " + key,
|
38
|
-
var dep = new ConstDependency(REPLACEMENTS[key], expr.range);
|
39
|
-
dep.loc = expr.loc;
|
40
|
-
this.state.current.addDependency(dep);
|
41
|
-
return true;
|
42
|
-
});
|
37
|
+
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(REPLACEMENTS[key]));
|
43
38
|
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));
|
44
39
|
});
|
45
40
|
});
|
@@ -2,101 +2,94 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
module.exports = FlagDependencyExportsPlugin;
|
7
|
+
class FlagDependencyExportsPlugin {
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
apply(compiler) {
|
10
|
+
compiler.plugin("compilation", (compilation) => {
|
11
|
+
compilation.plugin("finish-modules", (modules) => {
|
13
12
|
|
14
|
-
|
13
|
+
const dependencies = Object.create(null);
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
module = queue[i];
|
15
|
+
let module;
|
16
|
+
let moduleWithExports;
|
17
|
+
const queue = modules.filter((m) => !m.providedExports);
|
18
|
+
for(let i = 0; i < queue.length; i++) {
|
19
|
+
module = queue[i];
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
if(module.providedExports !== true) {
|
22
|
+
moduleWithExports = false;
|
23
|
+
processDependenciesBlock(module);
|
24
|
+
if(!moduleWithExports) {
|
25
|
+
module.providedExports = true;
|
26
|
+
notifyDependencies();
|
27
|
+
}
|
29
28
|
}
|
30
29
|
}
|
31
|
-
}
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
depBlock.variables.forEach(function(variable) {
|
38
|
-
variable.dependencies.forEach(function(dep) {
|
39
|
-
processDependency(dep);
|
40
|
-
});
|
41
|
-
});
|
42
|
-
depBlock.blocks.forEach(function(block) {
|
43
|
-
processDependenciesBlock(block);
|
44
|
-
});
|
45
|
-
}
|
46
|
-
|
47
|
-
function processDependency(dep, usedExports) {
|
48
|
-
var exportDesc = dep.getExports && dep.getExports();
|
49
|
-
if(!exportDesc) return;
|
50
|
-
moduleWithExports = true;
|
51
|
-
var exports = exportDesc.exports;
|
52
|
-
var exportDeps = exportDesc.dependencies;
|
53
|
-
if(exportDeps) {
|
54
|
-
exportDeps.forEach(function(dep) {
|
55
|
-
var depIdent = dep.identifier();
|
56
|
-
var array = dependencies["$" + depIdent];
|
57
|
-
if(!array) array = dependencies["$" + depIdent] = [];
|
58
|
-
if(array.indexOf(module) < 0)
|
59
|
-
array.push(module);
|
31
|
+
function processDependenciesBlock(depBlock) {
|
32
|
+
depBlock.dependencies.forEach((dep) => processDependency(dep));
|
33
|
+
depBlock.variables.forEach((variable) => {
|
34
|
+
variable.dependencies.forEach((dep) => processDependency(dep));
|
60
35
|
});
|
36
|
+
depBlock.blocks.forEach(processDependenciesBlock);
|
61
37
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
38
|
+
|
39
|
+
function processDependency(dep, usedExports) {
|
40
|
+
const exportDesc = dep.getExports && dep.getExports();
|
41
|
+
if(!exportDesc) return;
|
42
|
+
moduleWithExports = true;
|
43
|
+
const exports = exportDesc.exports;
|
44
|
+
const exportDeps = exportDesc.dependencies;
|
45
|
+
if(exportDeps) {
|
46
|
+
exportDeps.forEach((dep) => {
|
47
|
+
const depIdent = dep.identifier();
|
48
|
+
let array = dependencies[depIdent];
|
49
|
+
if(!array) array = dependencies[depIdent] = [];
|
50
|
+
if(array.indexOf(module) < 0)
|
51
|
+
array.push(module);
|
52
|
+
});
|
53
|
+
}
|
54
|
+
let changed = false;
|
55
|
+
if(module.providedExports !== true) {
|
56
|
+
if(exports === true) {
|
57
|
+
module.providedExports = true;
|
72
58
|
changed = true;
|
59
|
+
} else if(Array.isArray(exports)) {
|
60
|
+
if(Array.isArray(module.providedExports)) {
|
61
|
+
changed = addToSet(module.providedExports, exports);
|
62
|
+
} else {
|
63
|
+
module.providedExports = exports.slice();
|
64
|
+
changed = true;
|
65
|
+
}
|
73
66
|
}
|
74
67
|
}
|
68
|
+
if(changed) {
|
69
|
+
notifyDependencies();
|
70
|
+
}
|
75
71
|
}
|
76
|
-
if(changed) {
|
77
|
-
notifyDependencies();
|
78
|
-
}
|
79
|
-
}
|
80
72
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
});
|
73
|
+
function notifyDependencies() {
|
74
|
+
const deps = dependencies[module.identifier()];
|
75
|
+
if(deps) {
|
76
|
+
deps.forEach((dep) => queue.push(dep));
|
77
|
+
}
|
87
78
|
}
|
79
|
+
});
|
80
|
+
|
81
|
+
function addToSet(a, b) {
|
82
|
+
let changed = false;
|
83
|
+
b.forEach((item) => {
|
84
|
+
if(a.indexOf(item) < 0) {
|
85
|
+
a.push(item);
|
86
|
+
changed = true;
|
87
|
+
}
|
88
|
+
});
|
89
|
+
return changed;
|
88
90
|
}
|
89
91
|
});
|
92
|
+
}
|
93
|
+
}
|
90
94
|
|
91
|
-
|
92
|
-
var changed = false;
|
93
|
-
b.forEach(function(item) {
|
94
|
-
if(a.indexOf(item) < 0) {
|
95
|
-
a.push(item);
|
96
|
-
changed = true;
|
97
|
-
}
|
98
|
-
});
|
99
|
-
return changed;
|
100
|
-
}
|
101
|
-
});
|
102
|
-
};
|
95
|
+
module.exports = FlagDependencyExportsPlugin;
|
@@ -2,19 +2,23 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
|
7
|
-
FlagInitialModulesAsUsedPlugin
|
8
|
-
compiler
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
module
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
class FlagInitialModulesAsUsedPlugin {
|
8
|
+
apply(compiler) {
|
9
|
+
compiler.plugin("compilation", (compilation) => {
|
10
|
+
compilation.plugin("after-optimize-chunks", (chunks) => {
|
11
|
+
chunks.forEach((chunk) => {
|
12
|
+
if(!chunk.isInitial()) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
chunk.modules.forEach((module) => {
|
16
|
+
module.usedExports = true;
|
17
|
+
});
|
16
18
|
});
|
17
19
|
});
|
18
20
|
});
|
19
|
-
}
|
20
|
-
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
module.exports = FlagInitialModulesAsUsedPlugin;
|
@@ -2,17 +2,23 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var RequestShortener = require("./RequestShortener");
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
const FunctionModuleTemplatePlugin = require("./FunctionModuleTemplatePlugin");
|
8
|
+
const RequestShortener = require("./RequestShortener");
|
9
|
+
|
10
|
+
class FunctionModulePlugin {
|
11
|
+
constructor(options, requestShortener) {
|
12
|
+
this.options = options;
|
13
|
+
this.requestShortener = requestShortener;
|
14
|
+
}
|
15
|
+
|
16
|
+
apply(compiler) {
|
17
|
+
compiler.plugin("compilation", (compilation) => {
|
18
|
+
compilation.moduleTemplate.requestShortener = this.requestShortener || new RequestShortener(compiler.context);
|
19
|
+
compilation.moduleTemplate.apply(new FunctionModuleTemplatePlugin());
|
20
|
+
});
|
21
|
+
}
|
11
22
|
}
|
23
|
+
|
12
24
|
module.exports = FunctionModulePlugin;
|
13
|
-
FunctionModulePlugin.prototype.apply = function(compiler) {
|
14
|
-
compiler.plugin("compilation", function(compilation) {
|
15
|
-
compilation.moduleTemplate.requestShortener = this.requestShortener || new RequestShortener(compiler.context);
|
16
|
-
compilation.moduleTemplate.apply(new FunctionModuleTemplatePlugin());
|
17
|
-
}.bind(this));
|
18
|
-
};
|
@@ -4,7 +4,6 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
var Template = require("./Template");
|
7
|
-
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
8
7
|
var ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependency");
|
9
8
|
var ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency");
|
10
9
|
var RawSource = require("webpack-sources").RawSource;
|
@@ -197,17 +196,10 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|
197
196
|
});
|
198
197
|
|
199
198
|
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
|
200
|
-
parser.plugin("expression __webpack_hash__",
|
201
|
-
var dep = new ConstDependency("__webpack_require__.h()", expr.range);
|
202
|
-
dep.loc = expr.loc;
|
203
|
-
this.state.current.addDependency(dep);
|
204
|
-
return true;
|
205
|
-
});
|
199
|
+
parser.plugin("expression __webpack_hash__", ParserHelpers.toConstantDependency("__webpack_require__.h()"));
|
206
200
|
parser.plugin("evaluate typeof __webpack_hash__", ParserHelpers.evaluateToString("string"));
|
207
201
|
parser.plugin("evaluate Identifier module.hot", function(expr) {
|
208
|
-
return
|
209
|
-
.setBoolean(!!this.state.compilation.hotUpdateChunkTemplate)
|
210
|
-
.setRange(expr.range);
|
202
|
+
return ParserHelpers.evaluateToBoolean(!!this.state.compilation.hotUpdateChunkTemplate)(expr);
|
211
203
|
});
|
212
204
|
parser.plugin("call module.hot.accept", function(expr) {
|
213
205
|
if(!this.state.compilation.hotUpdateChunkTemplate) return false;
|
@@ -260,9 +252,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|
260
252
|
}.bind(this));
|
261
253
|
}
|
262
254
|
});
|
263
|
-
parser.plugin("expression module.hot",
|
264
|
-
return true;
|
265
|
-
});
|
255
|
+
parser.plugin("expression module.hot", ParserHelpers.skipTraversal);
|
266
256
|
});
|
267
257
|
});
|
268
258
|
|
@@ -2,30 +2,29 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
Template.call(this, outputOptions);
|
9
|
-
}
|
7
|
+
const Template = require("./Template");
|
10
8
|
|
11
|
-
module.exports = HotUpdateChunkTemplate
|
9
|
+
module.exports = class HotUpdateChunkTemplate extends Template {
|
10
|
+
constructor(outputOptions) {
|
11
|
+
super(outputOptions);
|
12
|
+
}
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
render(id, modules, removedModules, hash, moduleTemplate, dependencyTemplates) {
|
15
|
+
let modulesSource = this.renderChunkModules({
|
16
|
+
id: id,
|
17
|
+
modules: modules,
|
18
|
+
removedModules: removedModules
|
19
|
+
}, moduleTemplate, dependencyTemplates);
|
20
|
+
let core = this.applyPluginsWaterfall("modules", modulesSource, modules, removedModules, moduleTemplate, dependencyTemplates);
|
21
|
+
let source = this.applyPluginsWaterfall("render", core, modules, removedModules, hash, id, moduleTemplate, dependencyTemplates);
|
22
|
+
return source;
|
23
|
+
}
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}, moduleTemplate, dependencyTemplates);
|
22
|
-
var core = this.applyPluginsWaterfall("modules", modulesSource, modules, removedModules, moduleTemplate, dependencyTemplates);
|
23
|
-
var source = this.applyPluginsWaterfall("render", core, modules, removedModules, hash, id, moduleTemplate, dependencyTemplates);
|
24
|
-
return source;
|
25
|
-
};
|
26
|
-
|
27
|
-
HotUpdateChunkTemplate.prototype.updateHash = function(hash) {
|
28
|
-
hash.update("HotUpdateChunkTemplate");
|
29
|
-
hash.update("1");
|
30
|
-
this.applyPlugins("hash", hash);
|
25
|
+
updateHash(hash) {
|
26
|
+
hash.update("HotUpdateChunkTemplate");
|
27
|
+
hash.update("1");
|
28
|
+
this.applyPlugins("hash", hash);
|
29
|
+
}
|
31
30
|
};
|
@@ -2,16 +2,20 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const JsonpMainTemplatePlugin = require("./JsonpMainTemplatePlugin");
|
8
|
+
const JsonpChunkTemplatePlugin = require("./JsonpChunkTemplatePlugin");
|
9
|
+
const JsonpHotUpdateChunkTemplatePlugin = require("./JsonpHotUpdateChunkTemplatePlugin");
|
10
|
+
|
11
|
+
class JsonpTemplatePlugin {
|
12
|
+
apply(compiler) {
|
13
|
+
compiler.plugin("this-compilation", (compilation) => {
|
14
|
+
compilation.mainTemplate.apply(new JsonpMainTemplatePlugin());
|
15
|
+
compilation.chunkTemplate.apply(new JsonpChunkTemplatePlugin());
|
16
|
+
compilation.hotUpdateChunkTemplate.apply(new JsonpHotUpdateChunkTemplatePlugin());
|
17
|
+
});
|
18
|
+
}
|
19
|
+
}
|
8
20
|
|
9
|
-
function JsonpTemplatePlugin() {}
|
10
21
|
module.exports = JsonpTemplatePlugin;
|
11
|
-
JsonpTemplatePlugin.prototype.apply = function(compiler) {
|
12
|
-
compiler.plugin("this-compilation", function(compilation) {
|
13
|
-
compilation.mainTemplate.apply(new JsonpMainTemplatePlugin());
|
14
|
-
compilation.chunkTemplate.apply(new JsonpChunkTemplatePlugin());
|
15
|
-
compilation.hotUpdateChunkTemplate.apply(new JsonpHotUpdateChunkTemplatePlugin());
|
16
|
-
});
|
17
|
-
};
|
@@ -2,15 +2,19 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
class LoaderTargetPlugin {
|
8
|
+
constructor(target) {
|
9
|
+
this.target = target;
|
10
|
+
}
|
11
|
+
|
12
|
+
apply(compiler) {
|
13
|
+
let target = this.target;
|
14
|
+
compiler.plugin("compilation", (compilation) => {
|
15
|
+
compilation.plugin("normal-module-loader", (loaderContext) => loaderContext.target = target);
|
16
|
+
});
|
17
|
+
}
|
7
18
|
}
|
19
|
+
|
8
20
|
module.exports = LoaderTargetPlugin;
|
9
|
-
LoaderTargetPlugin.prototype.apply = function(compiler) {
|
10
|
-
var target = this.target;
|
11
|
-
compiler.plugin("compilation", function(compilation) {
|
12
|
-
compilation.plugin("normal-module-loader", function(loaderContext) {
|
13
|
-
loaderContext.target = target;
|
14
|
-
});
|
15
|
-
});
|
16
|
-
};
|