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,402 +1,406 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const ConcatSource = require("webpack-sources").ConcatSource;
8
- const OriginalSource = require("webpack-sources").OriginalSource;
9
- const PrefixSource = require("webpack-sources").PrefixSource;
10
- const RawSource = require("webpack-sources").RawSource;
11
- const Template = require("./Template");
12
- const Tapable = require("tapable").Tapable;
13
- const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
14
- const SyncHook = require("tapable").SyncHook;
15
- const SyncBailHook = require("tapable").SyncBailHook;
16
-
17
- // require function shortcuts:
18
- // __webpack_require__.s = the module id of the entry point
19
- // __webpack_require__.c = the module cache
20
- // __webpack_require__.m = the module functions
21
- // __webpack_require__.p = the bundle public path
22
- // __webpack_require__.i = the identity function used for harmony imports
23
- // __webpack_require__.e = the chunk ensure function
24
- // __webpack_require__.d = the exported property define getter function
25
- // __webpack_require__.o = Object.prototype.hasOwnProperty.call
26
- // __webpack_require__.r = define compatibility on export
27
- // __webpack_require__.n = compatibility get default export
28
- // __webpack_require__.h = the webpack hash
29
- // __webpack_require__.w = an object containing all installed WebAssembly.Modules keys by module id
30
- // __webpack_require__.oe = the uncaught error handler for the webpack runtime
31
- // __webpack_require__.nc = the script nonce
32
-
33
- module.exports = class MainTemplate extends Tapable {
34
- constructor(outputOptions) {
35
- super();
36
- this.outputOptions = outputOptions || {};
37
- this.hooks = {
38
- renderManifest: new SyncWaterfallHook(["result", "options"]),
39
- modules: new SyncWaterfallHook([
40
- "modules",
41
- "chunk",
42
- "hash",
43
- "moduleTemplate",
44
- "dependencyTemplates"
45
- ]),
46
- moduleObj: new SyncWaterfallHook([
47
- "source",
48
- "chunk",
49
- "hash",
50
- "moduleIdExpression"
51
- ]),
52
- requireEnsure: new SyncWaterfallHook([
53
- "source",
54
- "chunk",
55
- "hash",
56
- "chunkIdExpression"
57
- ]),
58
- bootstrap: new SyncWaterfallHook([
59
- "source",
60
- "chunk",
61
- "hash",
62
- "moduleTemplate",
63
- "dependencyTemplates"
64
- ]),
65
- localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
66
- require: new SyncWaterfallHook(["source", "chunk", "hash"]),
67
- requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
68
- beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
69
- startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
70
- render: new SyncWaterfallHook([
71
- "source",
72
- "chunk",
73
- "hash",
74
- "moduleTemplate",
75
- "dependencyTemplates"
76
- ]),
77
- renderWithEntry: new SyncWaterfallHook(["source", "chunk", "hash"]),
78
- moduleRequire: new SyncWaterfallHook([
79
- "source",
80
- "chunk",
81
- "hash",
82
- "moduleIdExpression"
83
- ]),
84
- addModule: new SyncWaterfallHook([
85
- "source",
86
- "chunk",
87
- "hash",
88
- "moduleIdExpression",
89
- "moduleExpression"
90
- ]),
91
- currentHash: new SyncWaterfallHook(["source", "requestedLength"]),
92
- assetPath: new SyncWaterfallHook(["path", "options"]),
93
- hash: new SyncHook(["hash"]),
94
- hashForChunk: new SyncHook(["hash", "chunk"]),
95
- globalHashPaths: new SyncWaterfallHook(["paths"]),
96
- globalHash: new SyncBailHook(["chunk", "paths"]),
97
-
98
- // TODO this should be moved somewhere else
99
- // It's weird here
100
- hotBootstrap: new SyncWaterfallHook(["source", "chunk", "hash"])
101
- };
102
- this.hooks.startup.tap("MainTemplate", (source, chunk, hash) => {
103
- const buf = [];
104
- if (chunk.entryModule) {
105
- buf.push("// Load entry module and return exports");
106
- buf.push(
107
- `return ${this.renderRequireFunctionForModule(
108
- hash,
109
- chunk,
110
- JSON.stringify(chunk.entryModule.id)
111
- )}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`
112
- );
113
- }
114
- return Template.asString(buf);
115
- });
116
- this.hooks.render.tap(
117
- "MainTemplate",
118
- (bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
119
- const source = new ConcatSource();
120
- source.add("/******/ (function(modules) { // webpackBootstrap\n");
121
- source.add(new PrefixSource("/******/", bootstrapSource));
122
- source.add("/******/ })\n");
123
- source.add(
124
- "/************************************************************************/\n"
125
- );
126
- source.add("/******/ (");
127
- source.add(
128
- this.hooks.modules.call(
129
- new RawSource(""),
130
- chunk,
131
- hash,
132
- moduleTemplate,
133
- dependencyTemplates
134
- )
135
- );
136
- source.add(")");
137
- return source;
138
- }
139
- );
140
- this.hooks.localVars.tap("MainTemplate", (source, chunk, hash) => {
141
- return Template.asString([
142
- source,
143
- "// The module cache",
144
- "var installedModules = {};"
145
- ]);
146
- });
147
- this.hooks.require.tap("MainTemplate", (source, chunk, hash) => {
148
- return Template.asString([
149
- source,
150
- "// Check if module is in cache",
151
- "if(installedModules[moduleId]) {",
152
- Template.indent("return installedModules[moduleId].exports;"),
153
- "}",
154
- "// Create a new module (and put it into the cache)",
155
- "var module = installedModules[moduleId] = {",
156
- Template.indent(this.hooks.moduleObj.call("", chunk, hash, "moduleId")),
157
- "};",
158
- "",
159
- Template.asString(
160
- outputOptions.strictModuleExceptionHandling
161
- ? [
162
- "// Execute the module function",
163
- "var threw = true;",
164
- "try {",
165
- Template.indent([
166
- `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
167
- hash,
168
- chunk,
169
- "moduleId"
170
- )});`,
171
- "threw = false;"
172
- ]),
173
- "} finally {",
174
- Template.indent([
175
- "if(threw) delete installedModules[moduleId];"
176
- ]),
177
- "}"
178
- ]
179
- : [
180
- "// Execute the module function",
181
- `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
182
- hash,
183
- chunk,
184
- "moduleId"
185
- )});`
186
- ]
187
- ),
188
- "",
189
- "// Flag the module as loaded",
190
- "module.l = true;",
191
- "",
192
- "// Return the exports of the module",
193
- "return module.exports;"
194
- ]);
195
- });
196
- this.hooks.moduleObj.tap(
197
- "MainTemplate",
198
- (source, chunk, hash, varModuleId) => {
199
- return Template.asString(["i: moduleId,", "l: false,", "exports: {}"]);
200
- }
201
- );
202
- this.hooks.requireExtensions.tap("MainTemplate", (source, chunk, hash) => {
203
- const buf = [];
204
- const chunkMaps = chunk.getChunkMaps();
205
- // Check if there are non initial chunks which need to be imported using require-ensure
206
- if (Object.keys(chunkMaps.hash).length) {
207
- buf.push("// This file contains only the entry chunk.");
208
- buf.push("// The chunk loading function for additional chunks");
209
- buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
210
- buf.push(Template.indent("var promises = [];"));
211
- buf.push(
212
- Template.indent(
213
- this.hooks.requireEnsure.call("", chunk, hash, "chunkId")
214
- )
215
- );
216
- buf.push(Template.indent("return Promise.all(promises);"));
217
- buf.push("};");
218
- }
219
- buf.push("");
220
- buf.push("// expose the modules object (__webpack_modules__)");
221
- buf.push(`${this.requireFn}.m = modules;`);
222
-
223
- buf.push("");
224
- buf.push("// expose the module cache");
225
- buf.push(`${this.requireFn}.c = installedModules;`);
226
-
227
- buf.push("");
228
- buf.push("// define getter function for harmony exports");
229
- buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
230
- buf.push(
231
- Template.indent([
232
- `if(!${this.requireFn}.o(exports, name)) {`,
233
- Template.indent([
234
- "Object.defineProperty(exports, name, {",
235
- Template.indent([
236
- "configurable: false,",
237
- "enumerable: true,",
238
- "get: getter"
239
- ]),
240
- "});"
241
- ]),
242
- "}"
243
- ])
244
- );
245
- buf.push("};");
246
-
247
- buf.push("");
248
- buf.push("// define __esModule on exports");
249
- buf.push(`${this.requireFn}.r = function(exports) {`);
250
- buf.push(
251
- Template.indent([
252
- "Object.defineProperty(exports, '__esModule', { value: true });"
253
- ])
254
- );
255
- buf.push("};");
256
-
257
- buf.push("");
258
- buf.push(
259
- "// getDefaultExport function for compatibility with non-harmony modules"
260
- );
261
- buf.push(this.requireFn + ".n = function(module) {");
262
- buf.push(
263
- Template.indent([
264
- "var getter = module && module.__esModule ?",
265
- Template.indent([
266
- "function getDefault() { return module['default']; } :",
267
- "function getModuleExports() { return module; };"
268
- ]),
269
- `${this.requireFn}.d(getter, 'a', getter);`,
270
- "return getter;"
271
- ])
272
- );
273
- buf.push("};");
274
-
275
- buf.push("");
276
- buf.push("// Object.prototype.hasOwnProperty.call");
277
- buf.push(
278
- `${
279
- this.requireFn
280
- }.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
281
- );
282
-
283
- const publicPath = this.getPublicPath({
284
- hash: hash
285
- });
286
- buf.push("");
287
- buf.push("// __webpack_public_path__");
288
- buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
289
- return Template.asString(buf);
290
- });
291
-
292
- this.requireFn = "__webpack_require__";
293
- }
294
-
295
- getRenderManifest(options) {
296
- const result = [];
297
-
298
- this.hooks.renderManifest.call(result, options);
299
-
300
- return result;
301
- }
302
-
303
- render(hash, chunk, moduleTemplate, dependencyTemplates) {
304
- const buf = [];
305
- buf.push(
306
- this.hooks.bootstrap.call(
307
- "",
308
- chunk,
309
- hash,
310
- moduleTemplate,
311
- dependencyTemplates
312
- )
313
- );
314
- buf.push(this.hooks.localVars.call("", chunk, hash));
315
- buf.push("");
316
- buf.push("// The require function");
317
- buf.push(`function ${this.requireFn}(moduleId) {`);
318
- buf.push(Template.indent(this.hooks.require.call("", chunk, hash)));
319
- buf.push("}");
320
- buf.push("");
321
- buf.push(
322
- Template.asString(this.hooks.requireExtensions.call("", chunk, hash))
323
- );
324
- buf.push("");
325
- buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
326
- buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
327
- let source = this.hooks.render.call(
328
- new OriginalSource(
329
- Template.prefix(buf, " \t") + "\n",
330
- "webpack/bootstrap"
331
- ),
332
- chunk,
333
- hash,
334
- moduleTemplate,
335
- dependencyTemplates
336
- );
337
- if (chunk.hasEntryModule()) {
338
- source = this.hooks.renderWithEntry.call(source, chunk, hash);
339
- }
340
- if (!source)
341
- throw new Error(
342
- "Compiler error: MainTemplate plugin 'render' should return something"
343
- );
344
- chunk.rendered = true;
345
- return new ConcatSource(source, ";");
346
- }
347
-
348
- renderRequireFunctionForModule(hash, chunk, varModuleId) {
349
- return this.hooks.moduleRequire.call(
350
- this.requireFn,
351
- chunk,
352
- hash,
353
- varModuleId
354
- );
355
- }
356
-
357
- renderAddModule(hash, chunk, varModuleId, varModule) {
358
- return this.hooks.addModule.call(
359
- `modules[${varModuleId}] = ${varModule};`,
360
- chunk,
361
- hash,
362
- varModuleId,
363
- varModule
364
- );
365
- }
366
-
367
- renderCurrentHashCode(hash, length) {
368
- length = length || Infinity;
369
- return this.hooks.currentHash.call(
370
- JSON.stringify(hash.substr(0, length)),
371
- length
372
- );
373
- }
374
-
375
- getPublicPath(options) {
376
- return this.hooks.assetPath.call(
377
- this.outputOptions.publicPath || "",
378
- options
379
- );
380
- }
381
-
382
- getAssetPath(path, options) {
383
- return this.hooks.assetPath.call(path, options);
384
- }
385
-
386
- updateHash(hash) {
387
- hash.update("maintemplate");
388
- hash.update("3");
389
- hash.update(this.outputOptions.publicPath + "");
390
- this.hooks.hash.call(hash);
391
- }
392
-
393
- updateHashForChunk(hash, chunk) {
394
- this.updateHash(hash);
395
- this.hooks.hashForChunk.call(hash, chunk);
396
- }
397
-
398
- useChunkHash(chunk) {
399
- const paths = this.hooks.globalHashPaths.call([]);
400
- return !this.hooks.globalHash.call(chunk, paths);
401
- }
402
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const {
8
+ ConcatSource,
9
+ OriginalSource,
10
+ PrefixSource,
11
+ RawSource
12
+ } = require("webpack-sources");
13
+ const {
14
+ Tapable,
15
+ SyncWaterfallHook,
16
+ SyncHook,
17
+ SyncBailHook
18
+ } = require("tapable");
19
+ const Template = require("./Template");
20
+
21
+ // require function shortcuts:
22
+ // __webpack_require__.s = the module id of the entry point
23
+ // __webpack_require__.c = the module cache
24
+ // __webpack_require__.m = the module functions
25
+ // __webpack_require__.p = the bundle public path
26
+ // __webpack_require__.i = the identity function used for harmony imports
27
+ // __webpack_require__.e = the chunk ensure function
28
+ // __webpack_require__.d = the exported property define getter function
29
+ // __webpack_require__.o = Object.prototype.hasOwnProperty.call
30
+ // __webpack_require__.r = define compatibility on export
31
+ // __webpack_require__.n = compatibility get default export
32
+ // __webpack_require__.h = the webpack hash
33
+ // __webpack_require__.w = an object containing all installed WebAssembly.Modules keys by module id
34
+ // __webpack_require__.oe = the uncaught error handler for the webpack runtime
35
+ // __webpack_require__.nc = the script nonce
36
+
37
+ module.exports = class MainTemplate extends Tapable {
38
+ constructor(outputOptions) {
39
+ super();
40
+ this.outputOptions = outputOptions || {};
41
+ this.hooks = {
42
+ renderManifest: new SyncWaterfallHook(["result", "options"]),
43
+ modules: new SyncWaterfallHook([
44
+ "modules",
45
+ "chunk",
46
+ "hash",
47
+ "moduleTemplate",
48
+ "dependencyTemplates"
49
+ ]),
50
+ moduleObj: new SyncWaterfallHook([
51
+ "source",
52
+ "chunk",
53
+ "hash",
54
+ "moduleIdExpression"
55
+ ]),
56
+ requireEnsure: new SyncWaterfallHook([
57
+ "source",
58
+ "chunk",
59
+ "hash",
60
+ "chunkIdExpression"
61
+ ]),
62
+ bootstrap: new SyncWaterfallHook([
63
+ "source",
64
+ "chunk",
65
+ "hash",
66
+ "moduleTemplate",
67
+ "dependencyTemplates"
68
+ ]),
69
+ localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
70
+ require: new SyncWaterfallHook(["source", "chunk", "hash"]),
71
+ requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
72
+ beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
73
+ startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
74
+ render: new SyncWaterfallHook([
75
+ "source",
76
+ "chunk",
77
+ "hash",
78
+ "moduleTemplate",
79
+ "dependencyTemplates"
80
+ ]),
81
+ renderWithEntry: new SyncWaterfallHook(["source", "chunk", "hash"]),
82
+ moduleRequire: new SyncWaterfallHook([
83
+ "source",
84
+ "chunk",
85
+ "hash",
86
+ "moduleIdExpression"
87
+ ]),
88
+ addModule: new SyncWaterfallHook([
89
+ "source",
90
+ "chunk",
91
+ "hash",
92
+ "moduleIdExpression",
93
+ "moduleExpression"
94
+ ]),
95
+ currentHash: new SyncWaterfallHook(["source", "requestedLength"]),
96
+ assetPath: new SyncWaterfallHook(["path", "options"]),
97
+ hash: new SyncHook(["hash"]),
98
+ hashForChunk: new SyncHook(["hash", "chunk"]),
99
+ globalHashPaths: new SyncWaterfallHook(["paths"]),
100
+ globalHash: new SyncBailHook(["chunk", "paths"]),
101
+
102
+ // TODO this should be moved somewhere else
103
+ // It's weird here
104
+ hotBootstrap: new SyncWaterfallHook(["source", "chunk", "hash"])
105
+ };
106
+ this.hooks.startup.tap("MainTemplate", (source, chunk, hash) => {
107
+ const buf = [];
108
+ if (chunk.entryModule) {
109
+ buf.push("// Load entry module and return exports");
110
+ buf.push(
111
+ `return ${this.renderRequireFunctionForModule(
112
+ hash,
113
+ chunk,
114
+ JSON.stringify(chunk.entryModule.id)
115
+ )}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`
116
+ );
117
+ }
118
+ return Template.asString(buf);
119
+ });
120
+ this.hooks.render.tap(
121
+ "MainTemplate",
122
+ (bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
123
+ const source = new ConcatSource();
124
+ source.add("/******/ (function(modules) { // webpackBootstrap\n");
125
+ source.add(new PrefixSource("/******/", bootstrapSource));
126
+ source.add("/******/ })\n");
127
+ source.add(
128
+ "/************************************************************************/\n"
129
+ );
130
+ source.add("/******/ (");
131
+ source.add(
132
+ this.hooks.modules.call(
133
+ new RawSource(""),
134
+ chunk,
135
+ hash,
136
+ moduleTemplate,
137
+ dependencyTemplates
138
+ )
139
+ );
140
+ source.add(")");
141
+ return source;
142
+ }
143
+ );
144
+ this.hooks.localVars.tap("MainTemplate", (source, chunk, hash) => {
145
+ return Template.asString([
146
+ source,
147
+ "// The module cache",
148
+ "var installedModules = {};"
149
+ ]);
150
+ });
151
+ this.hooks.require.tap("MainTemplate", (source, chunk, hash) => {
152
+ return Template.asString([
153
+ source,
154
+ "// Check if module is in cache",
155
+ "if(installedModules[moduleId]) {",
156
+ Template.indent("return installedModules[moduleId].exports;"),
157
+ "}",
158
+ "// Create a new module (and put it into the cache)",
159
+ "var module = installedModules[moduleId] = {",
160
+ Template.indent(this.hooks.moduleObj.call("", chunk, hash, "moduleId")),
161
+ "};",
162
+ "",
163
+ Template.asString(
164
+ outputOptions.strictModuleExceptionHandling
165
+ ? [
166
+ "// Execute the module function",
167
+ "var threw = true;",
168
+ "try {",
169
+ Template.indent([
170
+ `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
171
+ hash,
172
+ chunk,
173
+ "moduleId"
174
+ )});`,
175
+ "threw = false;"
176
+ ]),
177
+ "} finally {",
178
+ Template.indent([
179
+ "if(threw) delete installedModules[moduleId];"
180
+ ]),
181
+ "}"
182
+ ]
183
+ : [
184
+ "// Execute the module function",
185
+ `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
186
+ hash,
187
+ chunk,
188
+ "moduleId"
189
+ )});`
190
+ ]
191
+ ),
192
+ "",
193
+ "// Flag the module as loaded",
194
+ "module.l = true;",
195
+ "",
196
+ "// Return the exports of the module",
197
+ "return module.exports;"
198
+ ]);
199
+ });
200
+ this.hooks.moduleObj.tap(
201
+ "MainTemplate",
202
+ (source, chunk, hash, varModuleId) => {
203
+ return Template.asString(["i: moduleId,", "l: false,", "exports: {}"]);
204
+ }
205
+ );
206
+ this.hooks.requireExtensions.tap("MainTemplate", (source, chunk, hash) => {
207
+ const buf = [];
208
+ const chunkMaps = chunk.getChunkMaps();
209
+ // Check if there are non initial chunks which need to be imported using require-ensure
210
+ if (Object.keys(chunkMaps.hash).length) {
211
+ buf.push("// This file contains only the entry chunk.");
212
+ buf.push("// The chunk loading function for additional chunks");
213
+ buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
214
+ buf.push(Template.indent("var promises = [];"));
215
+ buf.push(
216
+ Template.indent(
217
+ this.hooks.requireEnsure.call("", chunk, hash, "chunkId")
218
+ )
219
+ );
220
+ buf.push(Template.indent("return Promise.all(promises);"));
221
+ buf.push("};");
222
+ }
223
+ buf.push("");
224
+ buf.push("// expose the modules object (__webpack_modules__)");
225
+ buf.push(`${this.requireFn}.m = modules;`);
226
+
227
+ buf.push("");
228
+ buf.push("// expose the module cache");
229
+ buf.push(`${this.requireFn}.c = installedModules;`);
230
+
231
+ buf.push("");
232
+ buf.push("// define getter function for harmony exports");
233
+ buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
234
+ buf.push(
235
+ Template.indent([
236
+ `if(!${this.requireFn}.o(exports, name)) {`,
237
+ Template.indent([
238
+ "Object.defineProperty(exports, name, {",
239
+ Template.indent([
240
+ "configurable: false,",
241
+ "enumerable: true,",
242
+ "get: getter"
243
+ ]),
244
+ "});"
245
+ ]),
246
+ "}"
247
+ ])
248
+ );
249
+ buf.push("};");
250
+
251
+ buf.push("");
252
+ buf.push("// define __esModule on exports");
253
+ buf.push(`${this.requireFn}.r = function(exports) {`);
254
+ buf.push(
255
+ Template.indent([
256
+ "Object.defineProperty(exports, '__esModule', { value: true });"
257
+ ])
258
+ );
259
+ buf.push("};");
260
+
261
+ buf.push("");
262
+ buf.push(
263
+ "// getDefaultExport function for compatibility with non-harmony modules"
264
+ );
265
+ buf.push(this.requireFn + ".n = function(module) {");
266
+ buf.push(
267
+ Template.indent([
268
+ "var getter = module && module.__esModule ?",
269
+ Template.indent([
270
+ "function getDefault() { return module['default']; } :",
271
+ "function getModuleExports() { return module; };"
272
+ ]),
273
+ `${this.requireFn}.d(getter, 'a', getter);`,
274
+ "return getter;"
275
+ ])
276
+ );
277
+ buf.push("};");
278
+
279
+ buf.push("");
280
+ buf.push("// Object.prototype.hasOwnProperty.call");
281
+ buf.push(
282
+ `${
283
+ this.requireFn
284
+ }.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
285
+ );
286
+
287
+ const publicPath = this.getPublicPath({
288
+ hash: hash
289
+ });
290
+ buf.push("");
291
+ buf.push("// __webpack_public_path__");
292
+ buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
293
+ return Template.asString(buf);
294
+ });
295
+
296
+ this.requireFn = "__webpack_require__";
297
+ }
298
+
299
+ getRenderManifest(options) {
300
+ const result = [];
301
+
302
+ this.hooks.renderManifest.call(result, options);
303
+
304
+ return result;
305
+ }
306
+
307
+ render(hash, chunk, moduleTemplate, dependencyTemplates) {
308
+ const buf = [];
309
+ buf.push(
310
+ this.hooks.bootstrap.call(
311
+ "",
312
+ chunk,
313
+ hash,
314
+ moduleTemplate,
315
+ dependencyTemplates
316
+ )
317
+ );
318
+ buf.push(this.hooks.localVars.call("", chunk, hash));
319
+ buf.push("");
320
+ buf.push("// The require function");
321
+ buf.push(`function ${this.requireFn}(moduleId) {`);
322
+ buf.push(Template.indent(this.hooks.require.call("", chunk, hash)));
323
+ buf.push("}");
324
+ buf.push("");
325
+ buf.push(
326
+ Template.asString(this.hooks.requireExtensions.call("", chunk, hash))
327
+ );
328
+ buf.push("");
329
+ buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
330
+ buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
331
+ let source = this.hooks.render.call(
332
+ new OriginalSource(
333
+ Template.prefix(buf, " \t") + "\n",
334
+ "webpack/bootstrap"
335
+ ),
336
+ chunk,
337
+ hash,
338
+ moduleTemplate,
339
+ dependencyTemplates
340
+ );
341
+ if (chunk.hasEntryModule()) {
342
+ source = this.hooks.renderWithEntry.call(source, chunk, hash);
343
+ }
344
+ if (!source)
345
+ throw new Error(
346
+ "Compiler error: MainTemplate plugin 'render' should return something"
347
+ );
348
+ chunk.rendered = true;
349
+ return new ConcatSource(source, ";");
350
+ }
351
+
352
+ renderRequireFunctionForModule(hash, chunk, varModuleId) {
353
+ return this.hooks.moduleRequire.call(
354
+ this.requireFn,
355
+ chunk,
356
+ hash,
357
+ varModuleId
358
+ );
359
+ }
360
+
361
+ renderAddModule(hash, chunk, varModuleId, varModule) {
362
+ return this.hooks.addModule.call(
363
+ `modules[${varModuleId}] = ${varModule};`,
364
+ chunk,
365
+ hash,
366
+ varModuleId,
367
+ varModule
368
+ );
369
+ }
370
+
371
+ renderCurrentHashCode(hash, length) {
372
+ length = length || Infinity;
373
+ return this.hooks.currentHash.call(
374
+ JSON.stringify(hash.substr(0, length)),
375
+ length
376
+ );
377
+ }
378
+
379
+ getPublicPath(options) {
380
+ return this.hooks.assetPath.call(
381
+ this.outputOptions.publicPath || "",
382
+ options
383
+ );
384
+ }
385
+
386
+ getAssetPath(path, options) {
387
+ return this.hooks.assetPath.call(path, options);
388
+ }
389
+
390
+ updateHash(hash) {
391
+ hash.update("maintemplate");
392
+ hash.update("3");
393
+ hash.update(this.outputOptions.publicPath + "");
394
+ this.hooks.hash.call(hash);
395
+ }
396
+
397
+ updateHashForChunk(hash, chunk) {
398
+ this.updateHash(hash);
399
+ this.hooks.hashForChunk.call(hash, chunk);
400
+ }
401
+
402
+ useChunkHash(chunk) {
403
+ const paths = this.hooks.globalHashPaths.call([]);
404
+ return !this.hooks.globalHash.call(chunk, paths);
405
+ }
406
+ };