webpack 4.1.0 → 4.4.0
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 +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,273 +1,320 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const Template = require("../Template");
|
8
|
-
|
9
|
-
module.exports = class NodeMainTemplatePlugin {
|
10
|
-
constructor(asyncChunkLoading) {
|
11
|
-
this.asyncChunkLoading = asyncChunkLoading;
|
12
|
-
}
|
13
|
-
|
14
|
-
apply(mainTemplate) {
|
15
|
-
const needChunkOnDemandLoadingCode = chunk => {
|
16
|
-
for (const chunkGroup of chunk.groupsIterable) {
|
17
|
-
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
18
|
-
}
|
19
|
-
return false;
|
20
|
-
};
|
21
|
-
const asyncChunkLoading = this.asyncChunkLoading;
|
22
|
-
mainTemplate.hooks.localVars.tap(
|
23
|
-
"NodeMainTemplatePlugin",
|
24
|
-
(source, chunk) => {
|
25
|
-
if (needChunkOnDemandLoadingCode(chunk)) {
|
26
|
-
return Template.asString([
|
27
|
-
source,
|
28
|
-
"",
|
29
|
-
"// object to store loaded chunks",
|
30
|
-
'// "0" means "already loaded"',
|
31
|
-
"var installedChunks = {",
|
32
|
-
Template.indent(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
const
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
"",
|
85
|
-
"
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
"
|
92
|
-
Template.indent([
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
].
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
"
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const Template = require("../Template");
|
8
|
+
|
9
|
+
module.exports = class NodeMainTemplatePlugin {
|
10
|
+
constructor(asyncChunkLoading) {
|
11
|
+
this.asyncChunkLoading = asyncChunkLoading;
|
12
|
+
}
|
13
|
+
|
14
|
+
apply(mainTemplate) {
|
15
|
+
const needChunkOnDemandLoadingCode = chunk => {
|
16
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
17
|
+
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
18
|
+
}
|
19
|
+
return false;
|
20
|
+
};
|
21
|
+
const asyncChunkLoading = this.asyncChunkLoading;
|
22
|
+
mainTemplate.hooks.localVars.tap(
|
23
|
+
"NodeMainTemplatePlugin",
|
24
|
+
(source, chunk) => {
|
25
|
+
if (needChunkOnDemandLoadingCode(chunk)) {
|
26
|
+
return Template.asString([
|
27
|
+
source,
|
28
|
+
"",
|
29
|
+
"// object to store loaded chunks",
|
30
|
+
'// "0" means "already loaded"',
|
31
|
+
"var installedChunks = {",
|
32
|
+
Template.indent(
|
33
|
+
chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
|
34
|
+
),
|
35
|
+
"};"
|
36
|
+
]);
|
37
|
+
}
|
38
|
+
return source;
|
39
|
+
}
|
40
|
+
);
|
41
|
+
mainTemplate.hooks.requireExtensions.tap(
|
42
|
+
"NodeMainTemplatePlugin",
|
43
|
+
(source, chunk) => {
|
44
|
+
if (needChunkOnDemandLoadingCode(chunk)) {
|
45
|
+
return Template.asString([
|
46
|
+
source,
|
47
|
+
"",
|
48
|
+
"// uncaught error handler for webpack runtime",
|
49
|
+
`${mainTemplate.requireFn}.oe = function(err) {`,
|
50
|
+
Template.indent([
|
51
|
+
"process.nextTick(function() {",
|
52
|
+
Template.indent(
|
53
|
+
"throw err; // catch this error by using import().catch()"
|
54
|
+
),
|
55
|
+
"});"
|
56
|
+
]),
|
57
|
+
"};"
|
58
|
+
]);
|
59
|
+
}
|
60
|
+
return source;
|
61
|
+
}
|
62
|
+
);
|
63
|
+
mainTemplate.hooks.requireEnsure.tap(
|
64
|
+
"NodeMainTemplatePlugin",
|
65
|
+
(source, chunk, hash) => {
|
66
|
+
const chunkFilename = mainTemplate.outputOptions.chunkFilename;
|
67
|
+
const chunkMaps = chunk.getChunkMaps();
|
68
|
+
const insertMoreModules = [
|
69
|
+
"var moreModules = chunk.modules, chunkIds = chunk.ids;",
|
70
|
+
"for(var moduleId in moreModules) {",
|
71
|
+
Template.indent(
|
72
|
+
mainTemplate.renderAddModule(
|
73
|
+
hash,
|
74
|
+
chunk,
|
75
|
+
"moduleId",
|
76
|
+
"moreModules[moduleId]"
|
77
|
+
)
|
78
|
+
),
|
79
|
+
"}"
|
80
|
+
];
|
81
|
+
if (asyncChunkLoading) {
|
82
|
+
return Template.asString([
|
83
|
+
source,
|
84
|
+
"",
|
85
|
+
"// ReadFile + VM.run chunk loading for javascript",
|
86
|
+
"",
|
87
|
+
"var installedChunkData = installedChunks[chunkId];",
|
88
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
89
|
+
Template.indent([
|
90
|
+
'// array of [resolve, reject, promise] means "currently loading"',
|
91
|
+
"if(installedChunkData) {",
|
92
|
+
Template.indent(["promises.push(installedChunkData[2]);"]),
|
93
|
+
"} else {",
|
94
|
+
Template.indent([
|
95
|
+
"// load the chunk and return promise to it",
|
96
|
+
"var promise = new Promise(function(resolve, reject) {",
|
97
|
+
Template.indent([
|
98
|
+
"installedChunkData = installedChunks[chunkId] = [resolve, reject];",
|
99
|
+
"var filename = __dirname + " +
|
100
|
+
mainTemplate.getAssetPath(
|
101
|
+
JSON.stringify(`/${chunkFilename}`),
|
102
|
+
{
|
103
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(
|
104
|
+
hash
|
105
|
+
)} + "`,
|
106
|
+
hashWithLength: length =>
|
107
|
+
`" + ${mainTemplate.renderCurrentHashCode(
|
108
|
+
hash,
|
109
|
+
length
|
110
|
+
)} + "`,
|
111
|
+
chunk: {
|
112
|
+
id: '" + chunkId + "',
|
113
|
+
hash: `" + ${JSON.stringify(
|
114
|
+
chunkMaps.hash
|
115
|
+
)}[chunkId] + "`,
|
116
|
+
hashWithLength: length => {
|
117
|
+
const shortChunkHashMap = {};
|
118
|
+
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
119
|
+
if (typeof chunkMaps.hash[chunkId] === "string")
|
120
|
+
shortChunkHashMap[chunkId] = chunkMaps.hash[
|
121
|
+
chunkId
|
122
|
+
].substr(0, length);
|
123
|
+
}
|
124
|
+
return `" + ${JSON.stringify(
|
125
|
+
shortChunkHashMap
|
126
|
+
)}[chunkId] + "`;
|
127
|
+
},
|
128
|
+
contentHash: {
|
129
|
+
javascript: `" + ${JSON.stringify(
|
130
|
+
chunkMaps.contentHash.javascript
|
131
|
+
)}[chunkId] + "`
|
132
|
+
},
|
133
|
+
contentHashWithLength: {
|
134
|
+
javascript: length => {
|
135
|
+
const shortContentHashMap = {};
|
136
|
+
const contentHash =
|
137
|
+
chunkMaps.contentHash.javascript;
|
138
|
+
for (const chunkId of Object.keys(contentHash)) {
|
139
|
+
if (typeof contentHash[chunkId] === "string") {
|
140
|
+
shortContentHashMap[chunkId] = contentHash[
|
141
|
+
chunkId
|
142
|
+
].substr(0, length);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
return `" + ${JSON.stringify(
|
146
|
+
shortContentHashMap
|
147
|
+
)}[chunkId] + "`;
|
148
|
+
}
|
149
|
+
},
|
150
|
+
name: `" + (${JSON.stringify(
|
151
|
+
chunkMaps.name
|
152
|
+
)}[chunkId]||chunkId) + "`
|
153
|
+
},
|
154
|
+
contentHashType: "javascript"
|
155
|
+
}
|
156
|
+
) +
|
157
|
+
";",
|
158
|
+
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
|
159
|
+
Template.indent(
|
160
|
+
[
|
161
|
+
"if(err) return reject(err);",
|
162
|
+
"var chunk = {};",
|
163
|
+
"require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
|
164
|
+
"(chunk, require, require('path').dirname(filename), filename);"
|
165
|
+
]
|
166
|
+
.concat(insertMoreModules)
|
167
|
+
.concat([
|
168
|
+
"var callbacks = [];",
|
169
|
+
"for(var i = 0; i < chunkIds.length; i++) {",
|
170
|
+
Template.indent([
|
171
|
+
"if(installedChunks[chunkIds[i]])",
|
172
|
+
Template.indent([
|
173
|
+
"callbacks = callbacks.concat(installedChunks[chunkIds[i]][0]);"
|
174
|
+
]),
|
175
|
+
"installedChunks[chunkIds[i]] = 0;"
|
176
|
+
]),
|
177
|
+
"}",
|
178
|
+
"for(i = 0; i < callbacks.length; i++)",
|
179
|
+
Template.indent("callbacks[i]();")
|
180
|
+
])
|
181
|
+
),
|
182
|
+
"});"
|
183
|
+
]),
|
184
|
+
"});",
|
185
|
+
"promises.push(installedChunkData[2] = promise);"
|
186
|
+
]),
|
187
|
+
"}"
|
188
|
+
]),
|
189
|
+
"}"
|
190
|
+
]);
|
191
|
+
} else {
|
192
|
+
const request = mainTemplate.getAssetPath(
|
193
|
+
JSON.stringify(`./${chunkFilename}`),
|
194
|
+
{
|
195
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
196
|
+
hashWithLength: length =>
|
197
|
+
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
198
|
+
chunk: {
|
199
|
+
id: '" + chunkId + "',
|
200
|
+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
201
|
+
hashWithLength: length => {
|
202
|
+
const shortChunkHashMap = {};
|
203
|
+
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
204
|
+
if (typeof chunkMaps.hash[chunkId] === "string")
|
205
|
+
shortChunkHashMap[chunkId] = chunkMaps.hash[
|
206
|
+
chunkId
|
207
|
+
].substr(0, length);
|
208
|
+
}
|
209
|
+
return `" + ${JSON.stringify(
|
210
|
+
shortChunkHashMap
|
211
|
+
)}[chunkId] + "`;
|
212
|
+
},
|
213
|
+
contentHash: {
|
214
|
+
javascript: `" + ${JSON.stringify(
|
215
|
+
chunkMaps.contentHash.javascript
|
216
|
+
)}[chunkId] + "`
|
217
|
+
},
|
218
|
+
contentHashWithLength: {
|
219
|
+
javascript: length => {
|
220
|
+
const shortContentHashMap = {};
|
221
|
+
const contentHash = chunkMaps.contentHash.javascript;
|
222
|
+
for (const chunkId of Object.keys(contentHash)) {
|
223
|
+
if (typeof contentHash[chunkId] === "string") {
|
224
|
+
shortContentHashMap[chunkId] = contentHash[
|
225
|
+
chunkId
|
226
|
+
].substr(0, length);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
return `" + ${JSON.stringify(
|
230
|
+
shortContentHashMap
|
231
|
+
)}[chunkId] + "`;
|
232
|
+
}
|
233
|
+
},
|
234
|
+
name: `" + (${JSON.stringify(
|
235
|
+
chunkMaps.name
|
236
|
+
)}[chunkId]||chunkId) + "`
|
237
|
+
},
|
238
|
+
contentHashType: "javascript"
|
239
|
+
}
|
240
|
+
);
|
241
|
+
return Template.asString([
|
242
|
+
source,
|
243
|
+
"",
|
244
|
+
"// require() chunk loading for javascript",
|
245
|
+
"",
|
246
|
+
'// "0" is the signal for "already loaded"',
|
247
|
+
"if(installedChunks[chunkId] !== 0) {",
|
248
|
+
Template.indent(
|
249
|
+
[`var chunk = require(${request});`]
|
250
|
+
.concat(insertMoreModules)
|
251
|
+
.concat([
|
252
|
+
"for(var i = 0; i < chunkIds.length; i++)",
|
253
|
+
Template.indent("installedChunks[chunkIds[i]] = 0;")
|
254
|
+
])
|
255
|
+
),
|
256
|
+
"}"
|
257
|
+
]);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
);
|
261
|
+
mainTemplate.hooks.hotBootstrap.tap(
|
262
|
+
"NodeMainTemplatePlugin",
|
263
|
+
(source, chunk, hash) => {
|
264
|
+
const hotUpdateChunkFilename =
|
265
|
+
mainTemplate.outputOptions.hotUpdateChunkFilename;
|
266
|
+
const hotUpdateMainFilename =
|
267
|
+
mainTemplate.outputOptions.hotUpdateMainFilename;
|
268
|
+
const chunkMaps = chunk.getChunkMaps();
|
269
|
+
const currentHotUpdateChunkFilename = mainTemplate.getAssetPath(
|
270
|
+
JSON.stringify(hotUpdateChunkFilename),
|
271
|
+
{
|
272
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
273
|
+
hashWithLength: length =>
|
274
|
+
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
275
|
+
chunk: {
|
276
|
+
id: '" + chunkId + "',
|
277
|
+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
278
|
+
hashWithLength: length => {
|
279
|
+
const shortChunkHashMap = {};
|
280
|
+
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
281
|
+
if (typeof chunkMaps.hash[chunkId] === "string")
|
282
|
+
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
|
283
|
+
0,
|
284
|
+
length
|
285
|
+
);
|
286
|
+
}
|
287
|
+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
288
|
+
},
|
289
|
+
name: `" + (${JSON.stringify(
|
290
|
+
chunkMaps.name
|
291
|
+
)}[chunkId]||chunkId) + "`
|
292
|
+
}
|
293
|
+
}
|
294
|
+
);
|
295
|
+
const currentHotUpdateMainFilename = mainTemplate.getAssetPath(
|
296
|
+
JSON.stringify(hotUpdateMainFilename),
|
297
|
+
{
|
298
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
299
|
+
hashWithLength: length =>
|
300
|
+
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
|
301
|
+
}
|
302
|
+
);
|
303
|
+
return Template.getFunctionContent(
|
304
|
+
asyncChunkLoading
|
305
|
+
? require("./NodeMainTemplateAsync.runtime.js")
|
306
|
+
: require("./NodeMainTemplate.runtime.js")
|
307
|
+
)
|
308
|
+
.replace(/\$require\$/g, mainTemplate.requireFn)
|
309
|
+
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
|
310
|
+
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename);
|
311
|
+
}
|
312
|
+
);
|
313
|
+
mainTemplate.hooks.hash.tap("NodeMainTemplatePlugin", hash => {
|
314
|
+
hash.update("node");
|
315
|
+
hash.update("3");
|
316
|
+
hash.update(mainTemplate.outputOptions.filename + "");
|
317
|
+
hash.update(mainTemplate.outputOptions.chunkFilename + "");
|
318
|
+
});
|
319
|
+
}
|
320
|
+
};
|