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,401 +1,401 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const OptionsApply = require("./OptionsApply");
8
-
9
- const JavascriptModulesPlugin = require("./JavascriptModulesPlugin");
10
- const JsonModulesPlugin = require("./JsonModulesPlugin");
11
- const WebAssemblyModulesPlugin = require("./WebAssemblyModulesPlugin");
12
-
13
- const LoaderTargetPlugin = require("./LoaderTargetPlugin");
14
- const FunctionModulePlugin = require("./FunctionModulePlugin");
15
- const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
16
- const SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
17
- const EvalSourceMapDevToolPlugin = require("./EvalSourceMapDevToolPlugin");
18
-
19
- const EntryOptionPlugin = require("./EntryOptionPlugin");
20
- const RecordIdsPlugin = require("./RecordIdsPlugin");
21
-
22
- const APIPlugin = require("./APIPlugin");
23
- const ConstPlugin = require("./ConstPlugin");
24
- const RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
25
- const NodeStuffPlugin = require("./NodeStuffPlugin");
26
- const CompatibilityPlugin = require("./CompatibilityPlugin");
27
-
28
- const TemplatedPathPlugin = require("./TemplatedPathPlugin");
29
- const WarnCaseSensitiveModulesPlugin = require("./WarnCaseSensitiveModulesPlugin");
30
- const UseStrictPlugin = require("./UseStrictPlugin");
31
-
32
- const LoaderPlugin = require("./dependencies/LoaderPlugin");
33
- const CommonJsPlugin = require("./dependencies/CommonJsPlugin");
34
- const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin");
35
- const SystemPlugin = require("./dependencies/SystemPlugin");
36
- const ImportPlugin = require("./dependencies/ImportPlugin");
37
- const AMDPlugin = require("./dependencies/AMDPlugin");
38
- const RequireContextPlugin = require("./dependencies/RequireContextPlugin");
39
- const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
40
- const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
41
-
42
- const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");
43
-
44
- const EnsureChunkConditionsPlugin = require("./optimize/EnsureChunkConditionsPlugin");
45
- const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
46
- const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
47
- const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
48
- const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
49
- const OccurrenceOrderPlugin = require("./optimize/OccurrenceOrderPlugin");
50
- const SideEffectsFlagPlugin = require("./optimize/SideEffectsFlagPlugin");
51
- const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
52
- const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
53
- const ModuleConcatenationPlugin = require("./optimize/ModuleConcatenationPlugin");
54
- const SplitChunksPlugin = require("./optimize/SplitChunksPlugin");
55
- const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
56
- const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
57
- const NamedModulesPlugin = require("./NamedModulesPlugin");
58
- const NamedChunksPlugin = require("./NamedChunksPlugin");
59
- const DefinePlugin = require("./DefinePlugin");
60
- const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");
61
-
62
- class WebpackOptionsApply extends OptionsApply {
63
- constructor() {
64
- super();
65
- }
66
-
67
- process(options, compiler) {
68
- let ExternalsPlugin;
69
- compiler.outputPath = options.output.path;
70
- compiler.recordsInputPath = options.recordsInputPath || options.recordsPath;
71
- compiler.recordsOutputPath =
72
- options.recordsOutputPath || options.recordsPath;
73
- compiler.name = options.name;
74
- compiler.dependencies = options.dependencies;
75
- if (typeof options.target === "string") {
76
- let JsonpTemplatePlugin;
77
- let FetchCompileWasmTemplatePlugin;
78
- let ReadFileCompileWasmTemplatePlugin;
79
- let NodeSourcePlugin;
80
- let NodeTargetPlugin;
81
- let NodeTemplatePlugin;
82
-
83
- switch (options.target) {
84
- case "web":
85
- JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
86
- FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
87
- NodeSourcePlugin = require("./node/NodeSourcePlugin");
88
- new JsonpTemplatePlugin(options.output).apply(compiler);
89
- new FetchCompileWasmTemplatePlugin(options.output).apply(compiler);
90
- new FunctionModulePlugin(options.output).apply(compiler);
91
- new NodeSourcePlugin(options.node).apply(compiler);
92
- new LoaderTargetPlugin(options.target).apply(compiler);
93
- break;
94
- case "webworker": {
95
- let WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
96
- FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
97
- NodeSourcePlugin = require("./node/NodeSourcePlugin");
98
- new WebWorkerTemplatePlugin().apply(compiler);
99
- new FetchCompileWasmTemplatePlugin(options.output).apply(compiler);
100
- new FunctionModulePlugin(options.output).apply(compiler);
101
- new NodeSourcePlugin(options.node).apply(compiler);
102
- new LoaderTargetPlugin(options.target).apply(compiler);
103
- break;
104
- }
105
- case "node":
106
- case "async-node":
107
- NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
108
- ReadFileCompileWasmTemplatePlugin = require("./node/ReadFileCompileWasmTemplatePlugin");
109
- NodeTargetPlugin = require("./node/NodeTargetPlugin");
110
- new NodeTemplatePlugin({
111
- asyncChunkLoading: options.target === "async-node"
112
- }).apply(compiler);
113
- new ReadFileCompileWasmTemplatePlugin(options.output).apply(compiler);
114
- new FunctionModulePlugin(options.output).apply(compiler);
115
- new NodeTargetPlugin().apply(compiler);
116
- new LoaderTargetPlugin("node").apply(compiler);
117
- break;
118
- case "node-webkit":
119
- JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
120
- NodeTargetPlugin = require("./node/NodeTargetPlugin");
121
- ExternalsPlugin = require("./ExternalsPlugin");
122
- new JsonpTemplatePlugin(options.output).apply(compiler);
123
- new FunctionModulePlugin(options.output).apply(compiler);
124
- new NodeTargetPlugin().apply(compiler);
125
- new ExternalsPlugin("commonjs", "nw.gui").apply(compiler);
126
- new LoaderTargetPlugin(options.target).apply(compiler);
127
- break;
128
- case "electron-main":
129
- NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
130
- NodeTargetPlugin = require("./node/NodeTargetPlugin");
131
- ExternalsPlugin = require("./ExternalsPlugin");
132
- new NodeTemplatePlugin({
133
- asyncChunkLoading: true
134
- }).apply(compiler);
135
- new FunctionModulePlugin(options.output).apply(compiler);
136
- new NodeTargetPlugin().apply(compiler);
137
- new ExternalsPlugin("commonjs", [
138
- "app",
139
- "auto-updater",
140
- "browser-window",
141
- "clipboard",
142
- "content-tracing",
143
- "crash-reporter",
144
- "dialog",
145
- "electron",
146
- "global-shortcut",
147
- "ipc",
148
- "ipc-main",
149
- "menu",
150
- "menu-item",
151
- "native-image",
152
- "original-fs",
153
- "power-monitor",
154
- "power-save-blocker",
155
- "protocol",
156
- "screen",
157
- "session",
158
- "shell",
159
- "tray",
160
- "web-contents"
161
- ]).apply(compiler);
162
- new LoaderTargetPlugin(options.target).apply(compiler);
163
- break;
164
- case "electron-renderer":
165
- JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
166
- NodeTargetPlugin = require("./node/NodeTargetPlugin");
167
- ExternalsPlugin = require("./ExternalsPlugin");
168
- new JsonpTemplatePlugin(options.output).apply(compiler);
169
- new FunctionModulePlugin(options.output).apply(compiler);
170
- new NodeTargetPlugin().apply(compiler);
171
- new ExternalsPlugin("commonjs", [
172
- "clipboard",
173
- "crash-reporter",
174
- "desktop-capturer",
175
- "electron",
176
- "ipc",
177
- "ipc-renderer",
178
- "native-image",
179
- "original-fs",
180
- "remote",
181
- "screen",
182
- "shell",
183
- "web-frame"
184
- ]).apply(compiler);
185
- new LoaderTargetPlugin(options.target).apply(compiler);
186
- break;
187
- default:
188
- throw new Error("Unsupported target '" + options.target + "'.");
189
- }
190
- } else if (options.target !== false) {
191
- options.target(compiler);
192
- } else {
193
- throw new Error("Unsupported target '" + options.target + "'.");
194
- }
195
-
196
- if (options.output.library || options.output.libraryTarget !== "var") {
197
- let LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
198
- new LibraryTemplatePlugin(
199
- options.output.library,
200
- options.output.libraryTarget,
201
- options.output.umdNamedDefine,
202
- options.output.auxiliaryComment || "",
203
- options.output.libraryExport
204
- ).apply(compiler);
205
- }
206
- if (options.externals) {
207
- ExternalsPlugin = require("./ExternalsPlugin");
208
- new ExternalsPlugin(
209
- options.output.libraryTarget,
210
- options.externals
211
- ).apply(compiler);
212
- }
213
-
214
- let noSources;
215
- let legacy;
216
- let modern;
217
- let comment;
218
- if (
219
- options.devtool &&
220
- (options.devtool.includes("sourcemap") ||
221
- options.devtool.includes("source-map"))
222
- ) {
223
- const hidden = options.devtool.includes("hidden");
224
- const inline = options.devtool.includes("inline");
225
- const evalWrapped = options.devtool.includes("eval");
226
- const cheap = options.devtool.includes("cheap");
227
- const moduleMaps = options.devtool.includes("module");
228
- noSources = options.devtool.includes("nosources");
229
- legacy = options.devtool.includes("@");
230
- modern = options.devtool.includes("#");
231
- comment =
232
- legacy && modern
233
- ? "\n/*\n//@ source" +
234
- "MappingURL=[url]\n//# source" +
235
- "MappingURL=[url]\n*/"
236
- : legacy
237
- ? "\n/*\n//@ source" + "MappingURL=[url]\n*/"
238
- : modern ? "\n//# source" + "MappingURL=[url]" : null;
239
- let Plugin = evalWrapped
240
- ? EvalSourceMapDevToolPlugin
241
- : SourceMapDevToolPlugin;
242
- new Plugin({
243
- filename: inline ? null : options.output.sourceMapFilename,
244
- moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
245
- fallbackModuleFilenameTemplate:
246
- options.output.devtoolFallbackModuleFilenameTemplate,
247
- append: hidden ? false : comment,
248
- module: moduleMaps ? true : cheap ? false : true,
249
- columns: cheap ? false : true,
250
- lineToLine: options.output.devtoolLineToLine,
251
- noSources: noSources,
252
- namespace: options.output.devtoolNamespace
253
- }).apply(compiler);
254
- } else if (options.devtool && options.devtool.includes("eval")) {
255
- legacy = options.devtool.includes("@");
256
- modern = options.devtool.includes("#");
257
- comment =
258
- legacy && modern
259
- ? "\n//@ sourceURL=[url]\n//# sourceURL=[url]"
260
- : legacy
261
- ? "\n//@ sourceURL=[url]"
262
- : modern ? "\n//# sourceURL=[url]" : null;
263
- new EvalDevToolModulePlugin({
264
- sourceUrlComment: comment,
265
- moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
266
- namespace: options.output.devtoolNamespace
267
- }).apply(compiler);
268
- }
269
-
270
- new JavascriptModulesPlugin().apply(compiler);
271
- new JsonModulesPlugin().apply(compiler);
272
- new WebAssemblyModulesPlugin().apply(compiler);
273
-
274
- new EntryOptionPlugin().apply(compiler);
275
- compiler.hooks.entryOption.call(options.context, options.entry);
276
-
277
- new CompatibilityPlugin().apply(compiler);
278
- new HarmonyModulesPlugin(options.module).apply(compiler);
279
- new AMDPlugin(options.module, options.amd || {}).apply(compiler);
280
- new CommonJsPlugin(options.module).apply(compiler);
281
- new LoaderPlugin().apply(compiler);
282
- new NodeStuffPlugin(options.node).apply(compiler);
283
- new RequireJsStuffPlugin().apply(compiler);
284
- new APIPlugin().apply(compiler);
285
- new ConstPlugin().apply(compiler);
286
- new UseStrictPlugin().apply(compiler);
287
- new RequireIncludePlugin().apply(compiler);
288
- new RequireEnsurePlugin().apply(compiler);
289
- new RequireContextPlugin(
290
- options.resolve.modules,
291
- options.resolve.extensions,
292
- options.resolve.mainFiles
293
- ).apply(compiler);
294
- new ImportPlugin(options.module).apply(compiler);
295
- new SystemPlugin(options.module).apply(compiler);
296
-
297
- if (typeof options.mode !== "string")
298
- new WarnNoModeSetPlugin().apply(compiler);
299
-
300
- new EnsureChunkConditionsPlugin().apply(compiler);
301
- if (options.optimization.removeAvailableModules)
302
- new RemoveParentModulesPlugin().apply(compiler);
303
- if (options.optimization.removeEmptyChunks)
304
- new RemoveEmptyChunksPlugin().apply(compiler);
305
- if (options.optimization.mergeDuplicateChunks)
306
- new MergeDuplicateChunksPlugin().apply(compiler);
307
- if (options.optimization.flagIncludedChunks)
308
- new FlagIncludedChunksPlugin().apply(compiler);
309
- if (options.optimization.occurrenceOrder)
310
- new OccurrenceOrderPlugin(true).apply(compiler);
311
- if (options.optimization.sideEffects)
312
- new SideEffectsFlagPlugin().apply(compiler);
313
- if (options.optimization.providedExports)
314
- new FlagDependencyExportsPlugin().apply(compiler);
315
- if (options.optimization.usedExports)
316
- new FlagDependencyUsagePlugin().apply(compiler);
317
- if (options.optimization.concatenateModules)
318
- new ModuleConcatenationPlugin().apply(compiler);
319
- if (options.optimization.splitChunks)
320
- new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
321
- if (options.optimization.runtimeChunk)
322
- new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
323
- if (options.optimization.noEmitOnErrors)
324
- new NoEmitOnErrorsPlugin().apply(compiler);
325
- if (options.optimization.namedModules)
326
- new NamedModulesPlugin().apply(compiler);
327
- if (options.optimization.namedChunks)
328
- new NamedChunksPlugin().apply(compiler);
329
- if (options.optimization.nodeEnv) {
330
- new DefinePlugin({
331
- "process.env.NODE_ENV": JSON.stringify(options.optimization.nodeEnv)
332
- }).apply(compiler);
333
- }
334
- if (options.optimization.minimize) {
335
- for (const minimizer of options.optimization.minimizer) {
336
- minimizer.apply(compiler);
337
- }
338
- }
339
-
340
- if (options.performance) {
341
- new SizeLimitsPlugin(options.performance).apply(compiler);
342
- }
343
-
344
- new TemplatedPathPlugin().apply(compiler);
345
-
346
- new RecordIdsPlugin({
347
- portableIds: options.optimization.portableRecords
348
- }).apply(compiler);
349
-
350
- new WarnCaseSensitiveModulesPlugin().apply(compiler);
351
-
352
- if (options.cache) {
353
- let CachePlugin = require("./CachePlugin");
354
- new CachePlugin(
355
- typeof options.cache === "object" ? options.cache : null
356
- ).apply(compiler);
357
- }
358
-
359
- compiler.hooks.afterPlugins.call(compiler);
360
- if (!compiler.inputFileSystem)
361
- throw new Error("No input filesystem provided");
362
- compiler.resolverFactory.hooks.resolveOptions
363
- .for("normal")
364
- .tap("WebpackOptionsApply", resolveOptions => {
365
- return Object.assign(
366
- {
367
- fileSystem: compiler.inputFileSystem
368
- },
369
- options.resolve,
370
- resolveOptions
371
- );
372
- });
373
- compiler.resolverFactory.hooks.resolveOptions
374
- .for("context")
375
- .tap("WebpackOptionsApply", resolveOptions => {
376
- return Object.assign(
377
- {
378
- fileSystem: compiler.inputFileSystem,
379
- resolveToContext: true
380
- },
381
- options.resolve,
382
- resolveOptions
383
- );
384
- });
385
- compiler.resolverFactory.hooks.resolveOptions
386
- .for("loader")
387
- .tap("WebpackOptionsApply", resolveOptions => {
388
- return Object.assign(
389
- {
390
- fileSystem: compiler.inputFileSystem
391
- },
392
- options.resolveLoader,
393
- resolveOptions
394
- );
395
- });
396
- compiler.hooks.afterResolvers.call(compiler);
397
- return options;
398
- }
399
- }
400
-
401
- module.exports = WebpackOptionsApply;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const OptionsApply = require("./OptionsApply");
8
+
9
+ const JavascriptModulesPlugin = require("./JavascriptModulesPlugin");
10
+ const JsonModulesPlugin = require("./JsonModulesPlugin");
11
+ const WebAssemblyModulesPlugin = require("./WebAssemblyModulesPlugin");
12
+
13
+ const LoaderTargetPlugin = require("./LoaderTargetPlugin");
14
+ const FunctionModulePlugin = require("./FunctionModulePlugin");
15
+ const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
16
+ const SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
17
+ const EvalSourceMapDevToolPlugin = require("./EvalSourceMapDevToolPlugin");
18
+
19
+ const EntryOptionPlugin = require("./EntryOptionPlugin");
20
+ const RecordIdsPlugin = require("./RecordIdsPlugin");
21
+
22
+ const APIPlugin = require("./APIPlugin");
23
+ const ConstPlugin = require("./ConstPlugin");
24
+ const RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
25
+ const NodeStuffPlugin = require("./NodeStuffPlugin");
26
+ const CompatibilityPlugin = require("./CompatibilityPlugin");
27
+
28
+ const TemplatedPathPlugin = require("./TemplatedPathPlugin");
29
+ const WarnCaseSensitiveModulesPlugin = require("./WarnCaseSensitiveModulesPlugin");
30
+ const UseStrictPlugin = require("./UseStrictPlugin");
31
+
32
+ const LoaderPlugin = require("./dependencies/LoaderPlugin");
33
+ const CommonJsPlugin = require("./dependencies/CommonJsPlugin");
34
+ const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin");
35
+ const SystemPlugin = require("./dependencies/SystemPlugin");
36
+ const ImportPlugin = require("./dependencies/ImportPlugin");
37
+ const AMDPlugin = require("./dependencies/AMDPlugin");
38
+ const RequireContextPlugin = require("./dependencies/RequireContextPlugin");
39
+ const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
40
+ const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
41
+
42
+ const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");
43
+
44
+ const EnsureChunkConditionsPlugin = require("./optimize/EnsureChunkConditionsPlugin");
45
+ const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
46
+ const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
47
+ const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
48
+ const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
49
+ const OccurrenceOrderPlugin = require("./optimize/OccurrenceOrderPlugin");
50
+ const SideEffectsFlagPlugin = require("./optimize/SideEffectsFlagPlugin");
51
+ const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
52
+ const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
53
+ const ModuleConcatenationPlugin = require("./optimize/ModuleConcatenationPlugin");
54
+ const SplitChunksPlugin = require("./optimize/SplitChunksPlugin");
55
+ const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
56
+ const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
57
+ const NamedModulesPlugin = require("./NamedModulesPlugin");
58
+ const NamedChunksPlugin = require("./NamedChunksPlugin");
59
+ const DefinePlugin = require("./DefinePlugin");
60
+ const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");
61
+
62
+ class WebpackOptionsApply extends OptionsApply {
63
+ constructor() {
64
+ super();
65
+ }
66
+
67
+ process(options, compiler) {
68
+ let ExternalsPlugin;
69
+ compiler.outputPath = options.output.path;
70
+ compiler.recordsInputPath = options.recordsInputPath || options.recordsPath;
71
+ compiler.recordsOutputPath =
72
+ options.recordsOutputPath || options.recordsPath;
73
+ compiler.name = options.name;
74
+ compiler.dependencies = options.dependencies;
75
+ if (typeof options.target === "string") {
76
+ let JsonpTemplatePlugin;
77
+ let FetchCompileWasmTemplatePlugin;
78
+ let ReadFileCompileWasmTemplatePlugin;
79
+ let NodeSourcePlugin;
80
+ let NodeTargetPlugin;
81
+ let NodeTemplatePlugin;
82
+
83
+ switch (options.target) {
84
+ case "web":
85
+ JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
86
+ FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
87
+ NodeSourcePlugin = require("./node/NodeSourcePlugin");
88
+ new JsonpTemplatePlugin(options.output).apply(compiler);
89
+ new FetchCompileWasmTemplatePlugin(options.output).apply(compiler);
90
+ new FunctionModulePlugin(options.output).apply(compiler);
91
+ new NodeSourcePlugin(options.node).apply(compiler);
92
+ new LoaderTargetPlugin(options.target).apply(compiler);
93
+ break;
94
+ case "webworker": {
95
+ let WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
96
+ FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
97
+ NodeSourcePlugin = require("./node/NodeSourcePlugin");
98
+ new WebWorkerTemplatePlugin().apply(compiler);
99
+ new FetchCompileWasmTemplatePlugin(options.output).apply(compiler);
100
+ new FunctionModulePlugin(options.output).apply(compiler);
101
+ new NodeSourcePlugin(options.node).apply(compiler);
102
+ new LoaderTargetPlugin(options.target).apply(compiler);
103
+ break;
104
+ }
105
+ case "node":
106
+ case "async-node":
107
+ NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
108
+ ReadFileCompileWasmTemplatePlugin = require("./node/ReadFileCompileWasmTemplatePlugin");
109
+ NodeTargetPlugin = require("./node/NodeTargetPlugin");
110
+ new NodeTemplatePlugin({
111
+ asyncChunkLoading: options.target === "async-node"
112
+ }).apply(compiler);
113
+ new ReadFileCompileWasmTemplatePlugin(options.output).apply(compiler);
114
+ new FunctionModulePlugin(options.output).apply(compiler);
115
+ new NodeTargetPlugin().apply(compiler);
116
+ new LoaderTargetPlugin("node").apply(compiler);
117
+ break;
118
+ case "node-webkit":
119
+ JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
120
+ NodeTargetPlugin = require("./node/NodeTargetPlugin");
121
+ ExternalsPlugin = require("./ExternalsPlugin");
122
+ new JsonpTemplatePlugin(options.output).apply(compiler);
123
+ new FunctionModulePlugin(options.output).apply(compiler);
124
+ new NodeTargetPlugin().apply(compiler);
125
+ new ExternalsPlugin("commonjs", "nw.gui").apply(compiler);
126
+ new LoaderTargetPlugin(options.target).apply(compiler);
127
+ break;
128
+ case "electron-main":
129
+ NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
130
+ NodeTargetPlugin = require("./node/NodeTargetPlugin");
131
+ ExternalsPlugin = require("./ExternalsPlugin");
132
+ new NodeTemplatePlugin({
133
+ asyncChunkLoading: true
134
+ }).apply(compiler);
135
+ new FunctionModulePlugin(options.output).apply(compiler);
136
+ new NodeTargetPlugin().apply(compiler);
137
+ new ExternalsPlugin("commonjs", [
138
+ "app",
139
+ "auto-updater",
140
+ "browser-window",
141
+ "clipboard",
142
+ "content-tracing",
143
+ "crash-reporter",
144
+ "dialog",
145
+ "electron",
146
+ "global-shortcut",
147
+ "ipc",
148
+ "ipc-main",
149
+ "menu",
150
+ "menu-item",
151
+ "native-image",
152
+ "original-fs",
153
+ "power-monitor",
154
+ "power-save-blocker",
155
+ "protocol",
156
+ "screen",
157
+ "session",
158
+ "shell",
159
+ "tray",
160
+ "web-contents"
161
+ ]).apply(compiler);
162
+ new LoaderTargetPlugin(options.target).apply(compiler);
163
+ break;
164
+ case "electron-renderer":
165
+ JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
166
+ NodeTargetPlugin = require("./node/NodeTargetPlugin");
167
+ ExternalsPlugin = require("./ExternalsPlugin");
168
+ new JsonpTemplatePlugin(options.output).apply(compiler);
169
+ new FunctionModulePlugin(options.output).apply(compiler);
170
+ new NodeTargetPlugin().apply(compiler);
171
+ new ExternalsPlugin("commonjs", [
172
+ "clipboard",
173
+ "crash-reporter",
174
+ "desktop-capturer",
175
+ "electron",
176
+ "ipc",
177
+ "ipc-renderer",
178
+ "native-image",
179
+ "original-fs",
180
+ "remote",
181
+ "screen",
182
+ "shell",
183
+ "web-frame"
184
+ ]).apply(compiler);
185
+ new LoaderTargetPlugin(options.target).apply(compiler);
186
+ break;
187
+ default:
188
+ throw new Error("Unsupported target '" + options.target + "'.");
189
+ }
190
+ } else if (options.target !== false) {
191
+ options.target(compiler);
192
+ } else {
193
+ throw new Error("Unsupported target '" + options.target + "'.");
194
+ }
195
+
196
+ if (options.output.library || options.output.libraryTarget !== "var") {
197
+ let LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
198
+ new LibraryTemplatePlugin(
199
+ options.output.library,
200
+ options.output.libraryTarget,
201
+ options.output.umdNamedDefine,
202
+ options.output.auxiliaryComment || "",
203
+ options.output.libraryExport
204
+ ).apply(compiler);
205
+ }
206
+ if (options.externals) {
207
+ ExternalsPlugin = require("./ExternalsPlugin");
208
+ new ExternalsPlugin(
209
+ options.output.libraryTarget,
210
+ options.externals
211
+ ).apply(compiler);
212
+ }
213
+
214
+ let noSources;
215
+ let legacy;
216
+ let modern;
217
+ let comment;
218
+ if (
219
+ options.devtool &&
220
+ (options.devtool.includes("sourcemap") ||
221
+ options.devtool.includes("source-map"))
222
+ ) {
223
+ const hidden = options.devtool.includes("hidden");
224
+ const inline = options.devtool.includes("inline");
225
+ const evalWrapped = options.devtool.includes("eval");
226
+ const cheap = options.devtool.includes("cheap");
227
+ const moduleMaps = options.devtool.includes("module");
228
+ noSources = options.devtool.includes("nosources");
229
+ legacy = options.devtool.includes("@");
230
+ modern = options.devtool.includes("#");
231
+ comment =
232
+ legacy && modern
233
+ ? "\n/*\n//@ source" +
234
+ "MappingURL=[url]\n//# source" +
235
+ "MappingURL=[url]\n*/"
236
+ : legacy
237
+ ? "\n/*\n//@ source" + "MappingURL=[url]\n*/"
238
+ : modern ? "\n//# source" + "MappingURL=[url]" : null;
239
+ let Plugin = evalWrapped
240
+ ? EvalSourceMapDevToolPlugin
241
+ : SourceMapDevToolPlugin;
242
+ new Plugin({
243
+ filename: inline ? null : options.output.sourceMapFilename,
244
+ moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
245
+ fallbackModuleFilenameTemplate:
246
+ options.output.devtoolFallbackModuleFilenameTemplate,
247
+ append: hidden ? false : comment,
248
+ module: moduleMaps ? true : cheap ? false : true,
249
+ columns: cheap ? false : true,
250
+ lineToLine: options.output.devtoolLineToLine,
251
+ noSources: noSources,
252
+ namespace: options.output.devtoolNamespace
253
+ }).apply(compiler);
254
+ } else if (options.devtool && options.devtool.includes("eval")) {
255
+ legacy = options.devtool.includes("@");
256
+ modern = options.devtool.includes("#");
257
+ comment =
258
+ legacy && modern
259
+ ? "\n//@ sourceURL=[url]\n//# sourceURL=[url]"
260
+ : legacy
261
+ ? "\n//@ sourceURL=[url]"
262
+ : modern ? "\n//# sourceURL=[url]" : null;
263
+ new EvalDevToolModulePlugin({
264
+ sourceUrlComment: comment,
265
+ moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
266
+ namespace: options.output.devtoolNamespace
267
+ }).apply(compiler);
268
+ }
269
+
270
+ new JavascriptModulesPlugin().apply(compiler);
271
+ new JsonModulesPlugin().apply(compiler);
272
+ new WebAssemblyModulesPlugin().apply(compiler);
273
+
274
+ new EntryOptionPlugin().apply(compiler);
275
+ compiler.hooks.entryOption.call(options.context, options.entry);
276
+
277
+ new CompatibilityPlugin().apply(compiler);
278
+ new HarmonyModulesPlugin(options.module).apply(compiler);
279
+ new AMDPlugin(options.module, options.amd || {}).apply(compiler);
280
+ new CommonJsPlugin(options.module).apply(compiler);
281
+ new LoaderPlugin().apply(compiler);
282
+ new NodeStuffPlugin(options.node).apply(compiler);
283
+ new RequireJsStuffPlugin().apply(compiler);
284
+ new APIPlugin().apply(compiler);
285
+ new ConstPlugin().apply(compiler);
286
+ new UseStrictPlugin().apply(compiler);
287
+ new RequireIncludePlugin().apply(compiler);
288
+ new RequireEnsurePlugin().apply(compiler);
289
+ new RequireContextPlugin(
290
+ options.resolve.modules,
291
+ options.resolve.extensions,
292
+ options.resolve.mainFiles
293
+ ).apply(compiler);
294
+ new ImportPlugin(options.module).apply(compiler);
295
+ new SystemPlugin(options.module).apply(compiler);
296
+
297
+ if (typeof options.mode !== "string")
298
+ new WarnNoModeSetPlugin().apply(compiler);
299
+
300
+ new EnsureChunkConditionsPlugin().apply(compiler);
301
+ if (options.optimization.removeAvailableModules)
302
+ new RemoveParentModulesPlugin().apply(compiler);
303
+ if (options.optimization.removeEmptyChunks)
304
+ new RemoveEmptyChunksPlugin().apply(compiler);
305
+ if (options.optimization.mergeDuplicateChunks)
306
+ new MergeDuplicateChunksPlugin().apply(compiler);
307
+ if (options.optimization.flagIncludedChunks)
308
+ new FlagIncludedChunksPlugin().apply(compiler);
309
+ if (options.optimization.occurrenceOrder)
310
+ new OccurrenceOrderPlugin(true).apply(compiler);
311
+ if (options.optimization.sideEffects)
312
+ new SideEffectsFlagPlugin().apply(compiler);
313
+ if (options.optimization.providedExports)
314
+ new FlagDependencyExportsPlugin().apply(compiler);
315
+ if (options.optimization.usedExports)
316
+ new FlagDependencyUsagePlugin().apply(compiler);
317
+ if (options.optimization.concatenateModules)
318
+ new ModuleConcatenationPlugin().apply(compiler);
319
+ if (options.optimization.splitChunks)
320
+ new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
321
+ if (options.optimization.runtimeChunk)
322
+ new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
323
+ if (options.optimization.noEmitOnErrors)
324
+ new NoEmitOnErrorsPlugin().apply(compiler);
325
+ if (options.optimization.namedModules)
326
+ new NamedModulesPlugin().apply(compiler);
327
+ if (options.optimization.namedChunks)
328
+ new NamedChunksPlugin().apply(compiler);
329
+ if (options.optimization.nodeEnv) {
330
+ new DefinePlugin({
331
+ "process.env.NODE_ENV": JSON.stringify(options.optimization.nodeEnv)
332
+ }).apply(compiler);
333
+ }
334
+ if (options.optimization.minimize) {
335
+ for (const minimizer of options.optimization.minimizer) {
336
+ minimizer.apply(compiler);
337
+ }
338
+ }
339
+
340
+ if (options.performance) {
341
+ new SizeLimitsPlugin(options.performance).apply(compiler);
342
+ }
343
+
344
+ new TemplatedPathPlugin().apply(compiler);
345
+
346
+ new RecordIdsPlugin({
347
+ portableIds: options.optimization.portableRecords
348
+ }).apply(compiler);
349
+
350
+ new WarnCaseSensitiveModulesPlugin().apply(compiler);
351
+
352
+ if (options.cache) {
353
+ let CachePlugin = require("./CachePlugin");
354
+ new CachePlugin(
355
+ typeof options.cache === "object" ? options.cache : null
356
+ ).apply(compiler);
357
+ }
358
+
359
+ compiler.hooks.afterPlugins.call(compiler);
360
+ if (!compiler.inputFileSystem)
361
+ throw new Error("No input filesystem provided");
362
+ compiler.resolverFactory.hooks.resolveOptions
363
+ .for("normal")
364
+ .tap("WebpackOptionsApply", resolveOptions => {
365
+ return Object.assign(
366
+ {
367
+ fileSystem: compiler.inputFileSystem
368
+ },
369
+ options.resolve,
370
+ resolveOptions
371
+ );
372
+ });
373
+ compiler.resolverFactory.hooks.resolveOptions
374
+ .for("context")
375
+ .tap("WebpackOptionsApply", resolveOptions => {
376
+ return Object.assign(
377
+ {
378
+ fileSystem: compiler.inputFileSystem,
379
+ resolveToContext: true
380
+ },
381
+ options.resolve,
382
+ resolveOptions
383
+ );
384
+ });
385
+ compiler.resolverFactory.hooks.resolveOptions
386
+ .for("loader")
387
+ .tap("WebpackOptionsApply", resolveOptions => {
388
+ return Object.assign(
389
+ {
390
+ fileSystem: compiler.inputFileSystem
391
+ },
392
+ options.resolveLoader,
393
+ resolveOptions
394
+ );
395
+ });
396
+ compiler.hooks.afterResolvers.call(compiler);
397
+ return options;
398
+ }
399
+ }
400
+
401
+ module.exports = WebpackOptionsApply;