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