webpack 2.3.3 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -133
- package/lib/APIPlugin.js +0 -6
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +30 -8
- package/lib/CachePlugin.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +6 -3
- package/lib/ChunkRenderError.js +3 -1
- package/lib/ChunkTemplate.js +2 -2
- package/lib/Compilation.js +17 -17
- package/lib/Compiler.js +30 -25
- package/lib/ContextModule.js +4 -3
- package/lib/ContextModuleFactory.js +5 -5
- package/lib/DelegatedModule.js +69 -63
- package/lib/DependenciesBlock.js +65 -59
- package/lib/Dependency.js +1 -0
- package/lib/EntryModuleNotFoundError.js +16 -10
- package/lib/ExtendedAPIPlugin.js +7 -2
- package/lib/ExternalModule.js +1 -1
- package/lib/ExternalModuleFactoryPlugin.js +26 -23
- package/lib/FlagDependencyUsagePlugin.js +63 -75
- package/lib/HotModuleReplacement.runtime.js +25 -27
- package/lib/HotModuleReplacementPlugin.js +3 -5
- package/lib/IgnorePlugin.js +48 -17
- package/lib/JsonpChunkTemplatePlugin.js +24 -24
- package/lib/JsonpMainTemplatePlugin.js +182 -182
- package/lib/LibManifestPlugin.js +51 -46
- package/lib/MainTemplate.js +17 -18
- package/lib/Module.js +158 -160
- package/lib/ModuleBuildError.js +4 -2
- package/lib/ModuleDependencyError.js +2 -1
- package/lib/ModuleDependencyWarning.js +2 -1
- package/lib/ModuleError.js +2 -2
- package/lib/ModuleFilenameHelpers.js +27 -27
- package/lib/ModuleNotFoundError.js +3 -1
- package/lib/ModuleParseError.js +6 -4
- package/lib/ModuleWarning.js +2 -2
- package/lib/MultiCompiler.js +3 -4
- package/lib/MultiStats.js +3 -3
- package/lib/MultiWatching.js +2 -2
- package/lib/NamedChunksPlugin.js +30 -0
- package/lib/NodeStuffPlugin.js +80 -79
- package/lib/NormalModule.js +7 -3
- package/lib/NormalModuleFactory.js +244 -240
- package/lib/Parser.js +1256 -1079
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +1 -1
- package/lib/RecordIdsPlugin.js +5 -9
- package/lib/SetVarMainTemplatePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +153 -157
- package/lib/Stats.js +34 -6
- package/lib/TemplatedPathPlugin.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +2 -1
- package/lib/WebpackError.js +11 -0
- package/lib/WebpackOptionsApply.js +4 -4
- package/lib/WebpackOptionsValidationError.js +2 -3
- package/lib/dependencies/AMDDefineDependency.js +10 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/ContextDependencyHelpers.js +19 -16
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/DepBlockHelpers.js +3 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportDependenciesBlock.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +16 -2
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
- package/lib/dependencies/RequireEnsureDependency.js +9 -2
- package/lib/formatLocation.js +44 -27
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
- package/lib/optimize/CommonsChunkPlugin.js +2 -2
- package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
- package/lib/performance/NoAsyncChunksWarning.js +5 -1
- package/lib/removeAndDo.js +6 -4
- package/lib/util/identifier.js +16 -0
- package/lib/webpack.js +2 -1
- package/package.json +7 -4
- package/schemas/webpackOptionsSchema.json +35 -0
@@ -2,207 +2,207 @@
|
|
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 = JsonpMainTemplatePlugin;
|
7
|
+
const Template = require("./Template");
|
9
8
|
|
10
|
-
JsonpMainTemplatePlugin
|
11
|
-
|
12
|
-
mainTemplate
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
"script.type = 'text/javascript';",
|
37
|
-
"script.charset = 'utf-8';",
|
38
|
-
"script.async = true;",
|
39
|
-
"script.timeout = " + chunkLoadTimeout + ";",
|
40
|
-
crossOriginLoading ? "script.crossOrigin = '" + crossOriginLoading + "';" : "",
|
41
|
-
"if (" + this.requireFn + ".nc) {",
|
42
|
-
this.indent("script.setAttribute(\"nonce\", " + this.requireFn + ".nc);"),
|
43
|
-
"}",
|
44
|
-
"script.src = " + this.requireFn + ".p + " +
|
45
|
-
this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
|
46
|
-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
|
47
|
-
hashWithLength: function(length) {
|
48
|
-
return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
|
49
|
-
}.bind(this),
|
9
|
+
class JsonpMainTemplatePlugin {
|
10
|
+
|
11
|
+
apply(mainTemplate) {
|
12
|
+
mainTemplate.plugin("local-vars", function(source, chunk) {
|
13
|
+
if(chunk.chunks.length > 0) {
|
14
|
+
return this.asString([
|
15
|
+
source,
|
16
|
+
"",
|
17
|
+
"// objects to store loaded and loading chunks",
|
18
|
+
"var installedChunks = {",
|
19
|
+
this.indent(
|
20
|
+
chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
|
21
|
+
),
|
22
|
+
"};"
|
23
|
+
]);
|
24
|
+
}
|
25
|
+
return source;
|
26
|
+
});
|
27
|
+
mainTemplate.plugin("jsonp-script", function(_, chunk, hash) {
|
28
|
+
const chunkFilename = this.outputOptions.chunkFilename;
|
29
|
+
const chunkMaps = chunk.getChunkMaps();
|
30
|
+
const crossOriginLoading = this.outputOptions.crossOriginLoading;
|
31
|
+
const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout || 120000;
|
32
|
+
const scriptSrcPath = this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
|
33
|
+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
|
34
|
+
hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
|
50
35
|
chunk: {
|
51
36
|
id: "\" + chunkId + \"",
|
52
|
-
hash: "
|
53
|
-
hashWithLength
|
54
|
-
|
55
|
-
Object.keys(chunkMaps.hash).forEach(
|
37
|
+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
38
|
+
hashWithLength(length) {
|
39
|
+
const shortChunkHashMap = Object.create(null);
|
40
|
+
Object.keys(chunkMaps.hash).forEach(chunkId => {
|
56
41
|
if(typeof chunkMaps.hash[chunkId] === "string")
|
57
42
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
58
43
|
});
|
59
|
-
return "
|
44
|
+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
60
45
|
},
|
61
|
-
name: "
|
46
|
+
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
62
47
|
}
|
63
|
-
})
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
"
|
48
|
+
});
|
49
|
+
return this.asString([
|
50
|
+
"var script = document.createElement('script');",
|
51
|
+
"script.type = 'text/javascript';",
|
52
|
+
"script.charset = 'utf-8';",
|
53
|
+
"script.async = true;",
|
54
|
+
`script.timeout = ${chunkLoadTimeout};`,
|
55
|
+
crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : "",
|
56
|
+
`if (${this.requireFn}.nc) {`,
|
57
|
+
this.indent(`script.setAttribute("nonce", ${this.requireFn}.nc);`),
|
58
|
+
"}",
|
59
|
+
`script.src = ${this.requireFn}.p + ${scriptSrcPath};`,
|
60
|
+
`var timeout = setTimeout(onScriptComplete, ${chunkLoadTimeout});`,
|
61
|
+
"script.onerror = script.onload = onScriptComplete;",
|
62
|
+
"function onScriptComplete() {",
|
73
63
|
this.indent([
|
74
|
-
"
|
75
|
-
"
|
64
|
+
"// avoid mem leaks in IE.",
|
65
|
+
"script.onerror = script.onload = null;",
|
66
|
+
"clearTimeout(timeout);",
|
67
|
+
"var chunk = installedChunks[chunkId];",
|
68
|
+
"if(chunk !== 0) {",
|
69
|
+
this.indent([
|
70
|
+
"if(chunk) {",
|
71
|
+
this.indent("chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));"),
|
72
|
+
"}",
|
73
|
+
"installedChunks[chunkId] = undefined;"
|
74
|
+
]),
|
75
|
+
"}"
|
76
76
|
]),
|
77
|
-
"}"
|
78
|
-
])
|
79
|
-
|
80
|
-
|
81
|
-
});
|
82
|
-
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
|
83
|
-
return this.asString([
|
84
|
-
"if(installedChunks[chunkId] === 0)",
|
85
|
-
this.indent([
|
86
|
-
"return Promise.resolve();"
|
87
|
-
]),
|
88
|
-
"",
|
89
|
-
"// a Promise means \"currently loading\".",
|
90
|
-
"if(installedChunks[chunkId]) {",
|
91
|
-
this.indent([
|
92
|
-
"return installedChunks[chunkId][2];"
|
93
|
-
]),
|
94
|
-
"}",
|
95
|
-
"",
|
96
|
-
"// setup Promise in chunk cache",
|
97
|
-
"var promise = new Promise(function(resolve, reject) {",
|
98
|
-
this.indent([
|
99
|
-
"installedChunks[chunkId] = [resolve, reject];"
|
100
|
-
]),
|
101
|
-
"});",
|
102
|
-
"installedChunks[chunkId][2] = promise;",
|
103
|
-
"",
|
104
|
-
"// start chunk loading",
|
105
|
-
"var head = document.getElementsByTagName('head')[0];",
|
106
|
-
this.applyPluginsWaterfall("jsonp-script", "", chunk, hash),
|
107
|
-
"head.appendChild(script);",
|
108
|
-
"",
|
109
|
-
"return promise;"
|
110
|
-
]);
|
111
|
-
});
|
112
|
-
mainTemplate.plugin("require-extensions", function(source, chunk) {
|
113
|
-
if(chunk.chunks.length === 0) return source;
|
114
|
-
return this.asString([
|
115
|
-
source,
|
116
|
-
"",
|
117
|
-
"// on error function for async loading",
|
118
|
-
this.requireFn + ".oe = function(err) { console.error(err); throw err; };"
|
119
|
-
]);
|
120
|
-
});
|
121
|
-
mainTemplate.plugin("bootstrap", function(source, chunk, hash) {
|
122
|
-
if(chunk.chunks.length > 0) {
|
123
|
-
var jsonpFunction = this.outputOptions.jsonpFunction;
|
77
|
+
"};",
|
78
|
+
]);
|
79
|
+
});
|
80
|
+
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
|
124
81
|
return this.asString([
|
125
|
-
|
82
|
+
"if(installedChunks[chunkId] === 0) {",
|
83
|
+
this.indent([
|
84
|
+
"return Promise.resolve();"
|
85
|
+
]),
|
86
|
+
"}",
|
126
87
|
"",
|
127
|
-
"//
|
128
|
-
"
|
129
|
-
"window[" + JSON.stringify(jsonpFunction) + "] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {",
|
88
|
+
"// a Promise means \"currently loading\".",
|
89
|
+
"if(installedChunks[chunkId]) {",
|
130
90
|
this.indent([
|
131
|
-
"
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
91
|
+
"return installedChunks[chunkId][2];"
|
92
|
+
]),
|
93
|
+
"}",
|
94
|
+
"",
|
95
|
+
"// setup Promise in chunk cache",
|
96
|
+
"var promise = new Promise(function(resolve, reject) {",
|
97
|
+
this.indent([
|
98
|
+
"installedChunks[chunkId] = [resolve, reject];"
|
99
|
+
]),
|
100
|
+
"});",
|
101
|
+
"installedChunks[chunkId][2] = promise;",
|
102
|
+
"",
|
103
|
+
"// start chunk loading",
|
104
|
+
"var head = document.getElementsByTagName('head')[0];",
|
105
|
+
this.applyPluginsWaterfall("jsonp-script", "", chunk, hash),
|
106
|
+
"head.appendChild(script);",
|
107
|
+
"",
|
108
|
+
"return promise;"
|
109
|
+
]);
|
110
|
+
});
|
111
|
+
mainTemplate.plugin("require-extensions", function(source, chunk) {
|
112
|
+
if(chunk.chunks.length === 0) return source;
|
113
|
+
|
114
|
+
return this.asString([
|
115
|
+
source,
|
116
|
+
"",
|
117
|
+
"// on error function for async loading",
|
118
|
+
`${this.requireFn}.oe = function(err) { console.error(err); throw err; };`
|
119
|
+
]);
|
120
|
+
});
|
121
|
+
mainTemplate.plugin("bootstrap", function(source, chunk, hash) {
|
122
|
+
if(chunk.chunks.length > 0) {
|
123
|
+
var jsonpFunction = this.outputOptions.jsonpFunction;
|
124
|
+
return this.asString([
|
125
|
+
source,
|
126
|
+
"",
|
127
|
+
"// install a JSONP callback for chunk loading",
|
128
|
+
`var parentJsonpFunction = window[${JSON.stringify(jsonpFunction)}];`,
|
129
|
+
`window[${JSON.stringify(jsonpFunction)}] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {`,
|
143
130
|
this.indent([
|
144
|
-
"
|
145
|
-
|
146
|
-
"
|
147
|
-
|
148
|
-
"}",
|
149
|
-
"if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);",
|
150
|
-
"while(resolves.length)",
|
151
|
-
this.indent("resolves.shift()();"),
|
152
|
-
this.entryPointInChildren(chunk) ? [
|
153
|
-
"if(executeModules) {",
|
131
|
+
"// add \"moreModules\" to the modules object,",
|
132
|
+
"// then flag all \"chunkIds\" as loaded and fire callback",
|
133
|
+
"var moduleId, chunkId, i = 0, resolves = [], result;",
|
134
|
+
"for(;i < chunkIds.length; i++) {",
|
154
135
|
this.indent([
|
155
|
-
"
|
156
|
-
|
136
|
+
"chunkId = chunkIds[i];",
|
137
|
+
"if(installedChunks[chunkId]) {",
|
138
|
+
this.indent("resolves.push(installedChunks[chunkId][0]);"),
|
139
|
+
"}",
|
140
|
+
"installedChunks[chunkId] = 0;"
|
141
|
+
]),
|
142
|
+
"}",
|
143
|
+
"for(moduleId in moreModules) {",
|
144
|
+
this.indent([
|
145
|
+
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
146
|
+
this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
|
157
147
|
"}"
|
158
148
|
]),
|
159
149
|
"}",
|
160
|
-
"
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
chunk: {
|
178
|
-
id: "\" + chunkId + \""
|
150
|
+
"if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);",
|
151
|
+
"while(resolves.length) {",
|
152
|
+
this.indent("resolves.shift()();"),
|
153
|
+
"}",
|
154
|
+
this.entryPointInChildren(chunk) ? [
|
155
|
+
"if(executeModules) {",
|
156
|
+
this.indent([
|
157
|
+
"for(i=0; i < executeModules.length; i++) {",
|
158
|
+
this.indent(`result = ${this.requireFn}(${this.requireFn}.s = executeModules[i]);`),
|
159
|
+
"}"
|
160
|
+
]),
|
161
|
+
"}",
|
162
|
+
"return result;",
|
163
|
+
] : ""
|
164
|
+
]),
|
165
|
+
"};"
|
166
|
+
]);
|
179
167
|
}
|
168
|
+
return source;
|
180
169
|
});
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
170
|
+
mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) {
|
171
|
+
const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
|
172
|
+
const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
|
173
|
+
const hotUpdateFunction = this.outputOptions.hotUpdateFunction;
|
174
|
+
const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
|
175
|
+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
|
176
|
+
hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
|
177
|
+
chunk: {
|
178
|
+
id: "\" + chunkId + \""
|
179
|
+
}
|
180
|
+
});
|
181
|
+
const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
|
182
|
+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
|
183
|
+
hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`
|
184
|
+
});
|
185
|
+
const runtimeSource = Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js"))
|
186
|
+
.replace(/\/\/\$semicolon/g, ";")
|
187
|
+
.replace(/\$require\$/g, this.requireFn)
|
188
|
+
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
|
189
|
+
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
|
190
|
+
.replace(/\$hash\$/g, JSON.stringify(hash));
|
191
|
+
return `${source}
|
192
|
+
function hotDisposeChunk(chunkId) {
|
193
|
+
delete installedChunks[chunkId];
|
194
|
+
}
|
195
|
+
var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];
|
196
|
+
this[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
186
197
|
});
|
187
|
-
|
188
|
-
|
189
|
-
"
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
.replace(/\$hash\$/g, JSON.stringify(hash));
|
199
|
-
});
|
200
|
-
mainTemplate.plugin("hash", function(hash) {
|
201
|
-
hash.update("jsonp");
|
202
|
-
hash.update("4");
|
203
|
-
hash.update(this.outputOptions.filename + "");
|
204
|
-
hash.update(this.outputOptions.chunkFilename + "");
|
205
|
-
hash.update(this.outputOptions.jsonpFunction + "");
|
206
|
-
hash.update(this.outputOptions.hotUpdateFunction + "");
|
207
|
-
});
|
208
|
-
};
|
198
|
+
mainTemplate.plugin("hash", function(hash) {
|
199
|
+
hash.update("jsonp");
|
200
|
+
hash.update("4");
|
201
|
+
hash.update(`${this.outputOptions.filename}`);
|
202
|
+
hash.update(`${this.outputOptions.chunkFilename}`);
|
203
|
+
hash.update(`${this.outputOptions.jsonpFunction}`);
|
204
|
+
hash.update(`${this.outputOptions.hotUpdateFunction}`);
|
205
|
+
});
|
206
|
+
}
|
207
|
+
}
|
208
|
+
module.exports = JsonpMainTemplatePlugin;
|
package/lib/LibManifestPlugin.js
CHANGED
@@ -2,52 +2,57 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var async = require("async");
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
const path = require("path");
|
8
|
+
const asyncLib = require("async");
|
9
|
+
|
10
|
+
class LibManifestPlugin {
|
11
|
+
constructor(options) {
|
12
|
+
this.options = options;
|
13
|
+
}
|
14
|
+
|
15
|
+
apply(compiler) {
|
16
|
+
compiler.plugin("emit", (compilation, callback) => {
|
17
|
+
asyncLib.forEach(compilation.chunks, (chunk, callback) => {
|
18
|
+
if(!chunk.isInitial()) {
|
19
|
+
callback();
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
const targetPath = compilation.getPath(this.options.path, {
|
23
|
+
hash: compilation.hash,
|
24
|
+
chunk
|
25
|
+
});
|
26
|
+
const name = this.options.name && compilation.getPath(this.options.name, {
|
27
|
+
hash: compilation.hash,
|
28
|
+
chunk
|
29
|
+
});
|
30
|
+
const manifest = {
|
31
|
+
name,
|
32
|
+
type: this.options.type,
|
33
|
+
content: chunk.modules.reduce((obj, module) => {
|
34
|
+
if(module.libIdent) {
|
35
|
+
const ident = module.libIdent({
|
36
|
+
context: this.options.context || compiler.options.context
|
37
|
+
});
|
38
|
+
if(ident) {
|
39
|
+
obj[ident] = {
|
40
|
+
id: module.id,
|
41
|
+
meta: module.meta,
|
42
|
+
exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
|
43
|
+
};
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return obj;
|
47
|
+
}, {})
|
48
|
+
};
|
49
|
+
const content = new Buffer(JSON.stringify(manifest), "utf8"); //eslint-disable-line
|
50
|
+
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
|
51
|
+
if(err) return callback(err);
|
52
|
+
compiler.outputFileSystem.writeFile(targetPath, content, callback);
|
53
|
+
});
|
54
|
+
}, callback);
|
55
|
+
});
|
56
|
+
}
|
10
57
|
}
|
11
58
|
module.exports = LibManifestPlugin;
|
12
|
-
LibManifestPlugin.prototype.apply = function(compiler) {
|
13
|
-
compiler.plugin("emit", function(compilation, callback) {
|
14
|
-
async.forEach(compilation.chunks, function(chunk, callback) {
|
15
|
-
if(!chunk.isInitial()) {
|
16
|
-
callback();
|
17
|
-
return;
|
18
|
-
}
|
19
|
-
var targetPath = compilation.getPath(this.options.path, {
|
20
|
-
hash: compilation.hash,
|
21
|
-
chunk: chunk
|
22
|
-
});
|
23
|
-
var name = this.options.name && compilation.getPath(this.options.name, {
|
24
|
-
hash: compilation.hash,
|
25
|
-
chunk: chunk
|
26
|
-
});
|
27
|
-
var manifest = {
|
28
|
-
name: name,
|
29
|
-
type: this.options.type,
|
30
|
-
content: chunk.modules.reduce(function(obj, module) {
|
31
|
-
if(module.libIdent) {
|
32
|
-
var ident = module.libIdent({
|
33
|
-
context: this.options.context || compiler.options.context
|
34
|
-
});
|
35
|
-
if(ident) {
|
36
|
-
obj[ident] = {
|
37
|
-
id: module.id,
|
38
|
-
meta: module.meta,
|
39
|
-
exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
|
40
|
-
};
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return obj;
|
44
|
-
}.bind(this), {})
|
45
|
-
};
|
46
|
-
var content = new Buffer(JSON.stringify(manifest, null, 2), "utf8"); //eslint-disable-line
|
47
|
-
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), function(err) {
|
48
|
-
if(err) return callback(err);
|
49
|
-
compiler.outputFileSystem.writeFile(targetPath, content, callback);
|
50
|
-
});
|
51
|
-
}.bind(this), callback);
|
52
|
-
}.bind(this));
|
53
|
-
};
|
package/lib/MainTemplate.js
CHANGED
@@ -30,8 +30,7 @@ module.exports = class MainTemplate extends Template {
|
|
30
30
|
const buf = [];
|
31
31
|
if(chunk.entryModule) {
|
32
32
|
buf.push("// Load entry module and return exports");
|
33
|
-
buf.push(
|
34
|
-
"(" + this.requireFn + ".s = " + JSON.stringify(chunk.entryModule.id) + ");");
|
33
|
+
buf.push(`return ${this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id))}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`);
|
35
34
|
}
|
36
35
|
return this.asString(buf);
|
37
36
|
});
|
@@ -58,9 +57,9 @@ module.exports = class MainTemplate extends Template {
|
|
58
57
|
return this.asString([
|
59
58
|
source,
|
60
59
|
"// Check if module is in cache",
|
61
|
-
"if(installedModules[moduleId])",
|
60
|
+
"if(installedModules[moduleId]) {",
|
62
61
|
this.indent("return installedModules[moduleId].exports;"),
|
63
|
-
"",
|
62
|
+
"}",
|
64
63
|
"// Create a new module (and put it into the cache)",
|
65
64
|
"var module = installedModules[moduleId] = {",
|
66
65
|
this.indent(this.applyPluginsWaterfall("module-obj", "", chunk, hash, "moduleId")),
|
@@ -71,7 +70,7 @@ module.exports = class MainTemplate extends Template {
|
|
71
70
|
"var threw = true;",
|
72
71
|
"try {",
|
73
72
|
this.indent([
|
74
|
-
|
73
|
+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
|
75
74
|
"threw = false;"
|
76
75
|
]),
|
77
76
|
"} finally {",
|
@@ -81,7 +80,7 @@ module.exports = class MainTemplate extends Template {
|
|
81
80
|
"}"
|
82
81
|
] : [
|
83
82
|
"// Execute the module function",
|
84
|
-
|
83
|
+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
|
85
84
|
]),
|
86
85
|
"",
|
87
86
|
"// Flag the module as loaded",
|
@@ -103,27 +102,27 @@ module.exports = class MainTemplate extends Template {
|
|
103
102
|
if(chunk.chunks.length > 0) {
|
104
103
|
buf.push("// This file contains only the entry chunk.");
|
105
104
|
buf.push("// The chunk loading function for additional chunks");
|
106
|
-
buf.push(this.requireFn
|
105
|
+
buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
|
107
106
|
buf.push(this.indent(this.applyPluginsWaterfall("require-ensure", "throw new Error('Not chunk loading available');", chunk, hash, "chunkId")));
|
108
107
|
buf.push("};");
|
109
108
|
}
|
110
109
|
buf.push("");
|
111
110
|
buf.push("// expose the modules object (__webpack_modules__)");
|
112
|
-
buf.push(this.requireFn
|
111
|
+
buf.push(`${this.requireFn}.m = modules;`);
|
113
112
|
|
114
113
|
buf.push("");
|
115
114
|
buf.push("// expose the module cache");
|
116
|
-
buf.push(this.requireFn
|
115
|
+
buf.push(`${this.requireFn}.c = installedModules;`);
|
117
116
|
|
118
117
|
buf.push("");
|
119
118
|
buf.push("// identity function for calling harmony imports with the correct context");
|
120
|
-
buf.push(this.requireFn
|
119
|
+
buf.push(`${this.requireFn}.i = function(value) { return value; };`);
|
121
120
|
|
122
121
|
buf.push("");
|
123
122
|
buf.push("// define getter function for harmony exports");
|
124
|
-
buf.push(this.requireFn
|
123
|
+
buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
|
125
124
|
buf.push(this.indent([
|
126
|
-
|
125
|
+
`if(!${this.requireFn}.o(exports, name)) {`,
|
127
126
|
this.indent([
|
128
127
|
"Object.defineProperty(exports, name, {",
|
129
128
|
this.indent([
|
@@ -146,21 +145,21 @@ module.exports = class MainTemplate extends Template {
|
|
146
145
|
"function getDefault() { return module['default']; } :",
|
147
146
|
"function getModuleExports() { return module; };"
|
148
147
|
]),
|
149
|
-
this.requireFn
|
148
|
+
`${this.requireFn}.d(getter, 'a', getter);`,
|
150
149
|
"return getter;"
|
151
150
|
]));
|
152
151
|
buf.push("};");
|
153
152
|
|
154
153
|
buf.push("");
|
155
154
|
buf.push("// Object.prototype.hasOwnProperty.call");
|
156
|
-
buf.push(this.requireFn
|
155
|
+
buf.push(`${this.requireFn}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`);
|
157
156
|
|
158
157
|
const publicPath = this.getPublicPath({
|
159
158
|
hash: hash
|
160
159
|
});
|
161
160
|
buf.push("");
|
162
161
|
buf.push("// __webpack_public_path__");
|
163
|
-
buf.push(this.requireFn
|
162
|
+
buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
|
164
163
|
return this.asString(buf);
|
165
164
|
});
|
166
165
|
|
@@ -173,14 +172,14 @@ module.exports = class MainTemplate extends Template {
|
|
173
172
|
buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
|
174
173
|
buf.push("");
|
175
174
|
buf.push("// The require function");
|
176
|
-
buf.push(
|
175
|
+
buf.push(`function ${this.requireFn}(moduleId) {`);
|
177
176
|
buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
|
178
177
|
buf.push("}");
|
179
178
|
buf.push("");
|
180
179
|
buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
|
181
180
|
buf.push("");
|
182
181
|
buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
|
183
|
-
let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n",
|
182
|
+
let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", `webpack/bootstrap ${hash}`), chunk, hash, moduleTemplate, dependencyTemplates);
|
184
183
|
if(chunk.hasEntryModule()) {
|
185
184
|
source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
|
186
185
|
}
|
@@ -194,7 +193,7 @@ module.exports = class MainTemplate extends Template {
|
|
194
193
|
}
|
195
194
|
|
196
195
|
renderAddModule(hash, chunk, varModuleId, varModule) {
|
197
|
-
return this.applyPluginsWaterfall("add-module",
|
196
|
+
return this.applyPluginsWaterfall("add-module", `modules[${varModuleId}] = ${varModule};`, chunk, hash, varModuleId, varModule);
|
198
197
|
}
|
199
198
|
|
200
199
|
renderCurrentHashCode(hash, length) {
|