1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const OptionsApply = require("./OptionsApply");
|
9 |
|
10 | const AssetModulesPlugin = require("./asset/AssetModulesPlugin");
|
11 | const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
12 | const JsonModulesPlugin = require("./json/JsonModulesPlugin");
|
13 |
|
14 | const ChunkPrefetchPreloadPlugin = require("./prefetch/ChunkPrefetchPreloadPlugin");
|
15 |
|
16 | const EntryOptionPlugin = require("./EntryOptionPlugin");
|
17 | const RecordIdsPlugin = require("./RecordIdsPlugin");
|
18 |
|
19 | const RuntimePlugin = require("./RuntimePlugin");
|
20 |
|
21 | const APIPlugin = require("./APIPlugin");
|
22 | const CompatibilityPlugin = require("./CompatibilityPlugin");
|
23 | const ConstPlugin = require("./ConstPlugin");
|
24 | const ExportsInfoApiPlugin = require("./ExportsInfoApiPlugin");
|
25 | const WebpackIsIncludedPlugin = require("./WebpackIsIncludedPlugin");
|
26 |
|
27 | const TemplatedPathPlugin = require("./TemplatedPathPlugin");
|
28 | const UseStrictPlugin = require("./UseStrictPlugin");
|
29 | const WarnCaseSensitiveModulesPlugin = require("./WarnCaseSensitiveModulesPlugin");
|
30 |
|
31 | const DataUriPlugin = require("./schemes/DataUriPlugin");
|
32 | const FileUriPlugin = require("./schemes/FileUriPlugin");
|
33 |
|
34 | const ResolverCachePlugin = require("./cache/ResolverCachePlugin");
|
35 |
|
36 | const CommonJsPlugin = require("./dependencies/CommonJsPlugin");
|
37 | const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin");
|
38 | const ImportMetaPlugin = require("./dependencies/ImportMetaPlugin");
|
39 | const ImportPlugin = require("./dependencies/ImportPlugin");
|
40 | const LoaderPlugin = require("./dependencies/LoaderPlugin");
|
41 | const RequireContextPlugin = require("./dependencies/RequireContextPlugin");
|
42 | const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
|
43 | const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
|
44 | const SystemPlugin = require("./dependencies/SystemPlugin");
|
45 | const URLPlugin = require("./dependencies/URLPlugin");
|
46 | const WorkerPlugin = require("./dependencies/WorkerPlugin");
|
47 |
|
48 | const InferAsyncModulesPlugin = require("./async-modules/InferAsyncModulesPlugin");
|
49 |
|
50 | const JavascriptMetaInfoPlugin = require("./JavascriptMetaInfoPlugin");
|
51 | const DefaultStatsFactoryPlugin = require("./stats/DefaultStatsFactoryPlugin");
|
52 | const DefaultStatsPresetPlugin = require("./stats/DefaultStatsPresetPlugin");
|
53 | const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
|
54 |
|
55 | const { cleverMerge } = require("./util/cleverMerge");
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | class WebpackOptionsApply extends OptionsApply {
|
61 | constructor() {
|
62 | super();
|
63 | }
|
64 |
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 | process(options, compiler) {
|
71 | compiler.outputPath = options.output.path;
|
72 | compiler.recordsInputPath = options.recordsInputPath || null;
|
73 | compiler.recordsOutputPath = options.recordsOutputPath || null;
|
74 | compiler.name = options.name;
|
75 |
|
76 | if (options.externals) {
|
77 |
|
78 | const ExternalsPlugin = require("./ExternalsPlugin");
|
79 | new ExternalsPlugin(options.externalsType, options.externals).apply(
|
80 | compiler
|
81 | );
|
82 | }
|
83 |
|
84 | if (options.externalsPresets.node) {
|
85 | const NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
86 | new NodeTargetPlugin().apply(compiler);
|
87 | }
|
88 | if (options.externalsPresets.electronMain) {
|
89 |
|
90 | const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
91 | new ElectronTargetPlugin("main").apply(compiler);
|
92 | }
|
93 | if (options.externalsPresets.electronPreload) {
|
94 |
|
95 | const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
96 | new ElectronTargetPlugin("preload").apply(compiler);
|
97 | }
|
98 | if (options.externalsPresets.electronRenderer) {
|
99 |
|
100 | const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
101 | new ElectronTargetPlugin("renderer").apply(compiler);
|
102 | }
|
103 | if (
|
104 | options.externalsPresets.electron &&
|
105 | !options.externalsPresets.electronMain &&
|
106 | !options.externalsPresets.electronPreload &&
|
107 | !options.externalsPresets.electronRenderer
|
108 | ) {
|
109 |
|
110 | const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
111 | new ElectronTargetPlugin().apply(compiler);
|
112 | }
|
113 | if (options.externalsPresets.nwjs) {
|
114 |
|
115 | const ExternalsPlugin = require("./ExternalsPlugin");
|
116 | new ExternalsPlugin("commonjs", "nw.gui").apply(compiler);
|
117 | }
|
118 | if (options.externalsPresets.webAsync) {
|
119 |
|
120 | const ExternalsPlugin = require("./ExternalsPlugin");
|
121 | new ExternalsPlugin("import", /^(https?:\/\/|std:)/).apply(compiler);
|
122 | } else if (options.externalsPresets.web) {
|
123 |
|
124 | const ExternalsPlugin = require("./ExternalsPlugin");
|
125 | new ExternalsPlugin("module", /^(https?:\/\/|std:)/).apply(compiler);
|
126 | }
|
127 |
|
128 | new ChunkPrefetchPreloadPlugin().apply(compiler);
|
129 |
|
130 | if (typeof options.output.chunkFormat === "string") {
|
131 | switch (options.output.chunkFormat) {
|
132 | case "array-push": {
|
133 | const ArrayPushCallbackChunkFormatPlugin = require("./javascript/ArrayPushCallbackChunkFormatPlugin");
|
134 | new ArrayPushCallbackChunkFormatPlugin().apply(compiler);
|
135 | break;
|
136 | }
|
137 | case "commonjs": {
|
138 | const CommonJsChunkFormatPlugin = require("./javascript/CommonJsChunkFormatPlugin");
|
139 | new CommonJsChunkFormatPlugin().apply(compiler);
|
140 | break;
|
141 | }
|
142 | case "module":
|
143 | throw new Error(
|
144 | "EcmaScript Module Chunk Format is not implemented yet"
|
145 | );
|
146 | default:
|
147 | throw new Error(
|
148 | "Unsupported chunk format '" + options.output.chunkFormat + "'."
|
149 | );
|
150 | }
|
151 | }
|
152 |
|
153 | if (options.output.enabledChunkLoadingTypes.length > 0) {
|
154 | for (const type of options.output.enabledChunkLoadingTypes) {
|
155 | const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
|
156 | new EnableChunkLoadingPlugin(type).apply(compiler);
|
157 | }
|
158 | }
|
159 |
|
160 | if (options.output.enabledWasmLoadingTypes.length > 0) {
|
161 | for (const type of options.output.enabledWasmLoadingTypes) {
|
162 | const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin");
|
163 | new EnableWasmLoadingPlugin(type).apply(compiler);
|
164 | }
|
165 | }
|
166 |
|
167 | if (options.output.enabledLibraryTypes.length > 0) {
|
168 | for (const type of options.output.enabledLibraryTypes) {
|
169 | const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
|
170 | new EnableLibraryPlugin(type).apply(compiler);
|
171 | }
|
172 | }
|
173 |
|
174 | if (options.output.pathinfo) {
|
175 | const ModuleInfoHeaderPlugin = require("./ModuleInfoHeaderPlugin");
|
176 | new ModuleInfoHeaderPlugin(options.output.pathinfo !== true).apply(
|
177 | compiler
|
178 | );
|
179 | }
|
180 |
|
181 | if (options.output.clean) {
|
182 | const CleanPlugin = require("./CleanPlugin");
|
183 | new CleanPlugin(
|
184 | options.output.clean === true ? {} : options.output.clean
|
185 | ).apply(compiler);
|
186 | }
|
187 |
|
188 | if (options.devtool) {
|
189 | if (options.devtool.includes("source-map")) {
|
190 | const hidden = options.devtool.includes("hidden");
|
191 | const inline = options.devtool.includes("inline");
|
192 | const evalWrapped = options.devtool.includes("eval");
|
193 | const cheap = options.devtool.includes("cheap");
|
194 | const moduleMaps = options.devtool.includes("module");
|
195 | const noSources = options.devtool.includes("nosources");
|
196 | const Plugin = evalWrapped
|
197 | ? require("./EvalSourceMapDevToolPlugin")
|
198 | : require("./SourceMapDevToolPlugin");
|
199 | new Plugin({
|
200 | filename: inline ? null : options.output.sourceMapFilename,
|
201 | moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
|
202 | fallbackModuleFilenameTemplate:
|
203 | options.output.devtoolFallbackModuleFilenameTemplate,
|
204 | append: hidden ? false : undefined,
|
205 | module: moduleMaps ? true : cheap ? false : true,
|
206 | columns: cheap ? false : true,
|
207 | noSources: noSources,
|
208 | namespace: options.output.devtoolNamespace
|
209 | }).apply(compiler);
|
210 | } else if (options.devtool.includes("eval")) {
|
211 | const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
|
212 | new EvalDevToolModulePlugin({
|
213 | moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
|
214 | namespace: options.output.devtoolNamespace
|
215 | }).apply(compiler);
|
216 | }
|
217 | }
|
218 |
|
219 | new JavascriptModulesPlugin().apply(compiler);
|
220 | new JsonModulesPlugin().apply(compiler);
|
221 | new AssetModulesPlugin().apply(compiler);
|
222 |
|
223 | if (!options.experiments.outputModule) {
|
224 | if (options.output.module) {
|
225 | throw new Error(
|
226 | "'output.module: true' is only allowed when 'experiments.outputModule' is enabled"
|
227 | );
|
228 | }
|
229 | if (options.output.enabledLibraryTypes.includes("module")) {
|
230 | throw new Error(
|
231 | "library type \"module\" is only allowed when 'experiments.outputModule' is enabled"
|
232 | );
|
233 | }
|
234 | if (options.externalsType === "module") {
|
235 | throw new Error(
|
236 | "'externalsType: \"module\"' is only allowed when 'experiments.outputModule' is enabled"
|
237 | );
|
238 | }
|
239 | }
|
240 |
|
241 | if (options.experiments.syncWebAssembly) {
|
242 | const WebAssemblyModulesPlugin = require("./wasm-sync/WebAssemblyModulesPlugin");
|
243 | new WebAssemblyModulesPlugin({
|
244 | mangleImports: options.optimization.mangleWasmImports
|
245 | }).apply(compiler);
|
246 | }
|
247 |
|
248 | if (options.experiments.asyncWebAssembly) {
|
249 | const AsyncWebAssemblyModulesPlugin = require("./wasm-async/AsyncWebAssemblyModulesPlugin");
|
250 | new AsyncWebAssemblyModulesPlugin({
|
251 | mangleImports: options.optimization.mangleWasmImports
|
252 | }).apply(compiler);
|
253 | }
|
254 |
|
255 | if (options.experiments.lazyCompilation) {
|
256 | const LazyCompilationPlugin = require("./hmr/LazyCompilationPlugin");
|
257 | const lazyOptions =
|
258 | typeof options.experiments.lazyCompilation === "object"
|
259 | ? options.experiments.lazyCompilation
|
260 | : null;
|
261 | new LazyCompilationPlugin({
|
262 | backend:
|
263 | (lazyOptions && lazyOptions.backend) ||
|
264 | require("./hmr/lazyCompilationBackend"),
|
265 | client:
|
266 | (lazyOptions && lazyOptions.client) ||
|
267 | require.resolve(
|
268 | `../hot/lazy-compilation-${
|
269 | options.externalsPresets.node ? "node" : "web"
|
270 | }.js`
|
271 | ),
|
272 | entries: !lazyOptions || lazyOptions.entries !== false,
|
273 | imports: !lazyOptions || lazyOptions.imports !== false,
|
274 | test: (lazyOptions && lazyOptions.test) || undefined
|
275 | }).apply(compiler);
|
276 | }
|
277 |
|
278 | new EntryOptionPlugin().apply(compiler);
|
279 | compiler.hooks.entryOption.call(options.context, options.entry);
|
280 |
|
281 | new RuntimePlugin().apply(compiler);
|
282 |
|
283 | new InferAsyncModulesPlugin().apply(compiler);
|
284 |
|
285 | new DataUriPlugin().apply(compiler);
|
286 | new FileUriPlugin().apply(compiler);
|
287 |
|
288 | new CompatibilityPlugin().apply(compiler);
|
289 | new HarmonyModulesPlugin({
|
290 | topLevelAwait: options.experiments.topLevelAwait
|
291 | }).apply(compiler);
|
292 | if (options.amd !== false) {
|
293 | const AMDPlugin = require("./dependencies/AMDPlugin");
|
294 | const RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
|
295 | new AMDPlugin(options.amd || {}).apply(compiler);
|
296 | new RequireJsStuffPlugin().apply(compiler);
|
297 | }
|
298 | new CommonJsPlugin().apply(compiler);
|
299 | new LoaderPlugin().apply(compiler);
|
300 | if (options.node !== false) {
|
301 | const NodeStuffPlugin = require("./NodeStuffPlugin");
|
302 | new NodeStuffPlugin(options.node).apply(compiler);
|
303 | }
|
304 | new APIPlugin().apply(compiler);
|
305 | new ExportsInfoApiPlugin().apply(compiler);
|
306 | new WebpackIsIncludedPlugin().apply(compiler);
|
307 | new ConstPlugin().apply(compiler);
|
308 | new UseStrictPlugin().apply(compiler);
|
309 | new RequireIncludePlugin().apply(compiler);
|
310 | new RequireEnsurePlugin().apply(compiler);
|
311 | new RequireContextPlugin().apply(compiler);
|
312 | new ImportPlugin().apply(compiler);
|
313 | new SystemPlugin().apply(compiler);
|
314 | new ImportMetaPlugin().apply(compiler);
|
315 | new URLPlugin().apply(compiler);
|
316 | new WorkerPlugin(
|
317 | options.output.workerChunkLoading,
|
318 | options.output.workerWasmLoading
|
319 | ).apply(compiler);
|
320 |
|
321 | new DefaultStatsFactoryPlugin().apply(compiler);
|
322 | new DefaultStatsPresetPlugin().apply(compiler);
|
323 | new DefaultStatsPrinterPlugin().apply(compiler);
|
324 |
|
325 | new JavascriptMetaInfoPlugin().apply(compiler);
|
326 |
|
327 | if (typeof options.mode !== "string") {
|
328 | const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");
|
329 | new WarnNoModeSetPlugin().apply(compiler);
|
330 | }
|
331 |
|
332 | const EnsureChunkConditionsPlugin = require("./optimize/EnsureChunkConditionsPlugin");
|
333 | new EnsureChunkConditionsPlugin().apply(compiler);
|
334 | if (options.optimization.removeAvailableModules) {
|
335 | const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
|
336 | new RemoveParentModulesPlugin().apply(compiler);
|
337 | }
|
338 | if (options.optimization.removeEmptyChunks) {
|
339 | const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
340 | new RemoveEmptyChunksPlugin().apply(compiler);
|
341 | }
|
342 | if (options.optimization.mergeDuplicateChunks) {
|
343 | const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
344 | new MergeDuplicateChunksPlugin().apply(compiler);
|
345 | }
|
346 | if (options.optimization.flagIncludedChunks) {
|
347 | const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
348 | new FlagIncludedChunksPlugin().apply(compiler);
|
349 | }
|
350 | if (options.optimization.sideEffects) {
|
351 | const SideEffectsFlagPlugin = require("./optimize/SideEffectsFlagPlugin");
|
352 | new SideEffectsFlagPlugin(
|
353 | options.optimization.sideEffects === true
|
354 | ).apply(compiler);
|
355 | }
|
356 | if (options.optimization.providedExports) {
|
357 | const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
|
358 | new FlagDependencyExportsPlugin().apply(compiler);
|
359 | }
|
360 | if (options.optimization.usedExports) {
|
361 | const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
|
362 | new FlagDependencyUsagePlugin(
|
363 | options.optimization.usedExports === "global"
|
364 | ).apply(compiler);
|
365 | }
|
366 | if (options.optimization.innerGraph) {
|
367 | const InnerGraphPlugin = require("./optimize/InnerGraphPlugin");
|
368 | new InnerGraphPlugin().apply(compiler);
|
369 | }
|
370 | if (options.optimization.mangleExports) {
|
371 | const MangleExportsPlugin = require("./optimize/MangleExportsPlugin");
|
372 | new MangleExportsPlugin(
|
373 | options.optimization.mangleExports !== "size"
|
374 | ).apply(compiler);
|
375 | }
|
376 | if (options.optimization.concatenateModules) {
|
377 | const ModuleConcatenationPlugin = require("./optimize/ModuleConcatenationPlugin");
|
378 | new ModuleConcatenationPlugin().apply(compiler);
|
379 | }
|
380 | if (options.optimization.splitChunks) {
|
381 | const SplitChunksPlugin = require("./optimize/SplitChunksPlugin");
|
382 | new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
|
383 | }
|
384 | if (options.optimization.runtimeChunk) {
|
385 | const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
|
386 | new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
|
387 | }
|
388 | if (!options.optimization.emitOnErrors) {
|
389 | const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
|
390 | new NoEmitOnErrorsPlugin().apply(compiler);
|
391 | }
|
392 | if (options.optimization.realContentHash) {
|
393 | const RealContentHashPlugin = require("./optimize/RealContentHashPlugin");
|
394 | new RealContentHashPlugin({
|
395 | hashFunction: options.output.hashFunction,
|
396 | hashDigest: options.output.hashDigest
|
397 | }).apply(compiler);
|
398 | }
|
399 | if (options.optimization.checkWasmTypes) {
|
400 | const WasmFinalizeExportsPlugin = require("./wasm-sync/WasmFinalizeExportsPlugin");
|
401 | new WasmFinalizeExportsPlugin().apply(compiler);
|
402 | }
|
403 | const moduleIds = options.optimization.moduleIds;
|
404 | if (moduleIds) {
|
405 | switch (moduleIds) {
|
406 | case "natural": {
|
407 | const NaturalModuleIdsPlugin = require("./ids/NaturalModuleIdsPlugin");
|
408 | new NaturalModuleIdsPlugin().apply(compiler);
|
409 | break;
|
410 | }
|
411 | case "named": {
|
412 | const NamedModuleIdsPlugin = require("./ids/NamedModuleIdsPlugin");
|
413 | new NamedModuleIdsPlugin().apply(compiler);
|
414 | break;
|
415 | }
|
416 | case "hashed": {
|
417 | const WarnDeprecatedOptionPlugin = require("./WarnDeprecatedOptionPlugin");
|
418 | const HashedModuleIdsPlugin = require("./ids/HashedModuleIdsPlugin");
|
419 | new WarnDeprecatedOptionPlugin(
|
420 | "optimization.moduleIds",
|
421 | "hashed",
|
422 | "deterministic"
|
423 | ).apply(compiler);
|
424 | new HashedModuleIdsPlugin().apply(compiler);
|
425 | break;
|
426 | }
|
427 | case "deterministic": {
|
428 | const DeterministicModuleIdsPlugin = require("./ids/DeterministicModuleIdsPlugin");
|
429 | new DeterministicModuleIdsPlugin().apply(compiler);
|
430 | break;
|
431 | }
|
432 | case "size": {
|
433 | const OccurrenceModuleIdsPlugin = require("./ids/OccurrenceModuleIdsPlugin");
|
434 | new OccurrenceModuleIdsPlugin({
|
435 | prioritiseInitial: true
|
436 | }).apply(compiler);
|
437 | break;
|
438 | }
|
439 | default:
|
440 | throw new Error(
|
441 | `webpack bug: moduleIds: ${moduleIds} is not implemented`
|
442 | );
|
443 | }
|
444 | }
|
445 | const chunkIds = options.optimization.chunkIds;
|
446 | if (chunkIds) {
|
447 | switch (chunkIds) {
|
448 | case "natural": {
|
449 | const NaturalChunkIdsPlugin = require("./ids/NaturalChunkIdsPlugin");
|
450 | new NaturalChunkIdsPlugin().apply(compiler);
|
451 | break;
|
452 | }
|
453 | case "named": {
|
454 | const NamedChunkIdsPlugin = require("./ids/NamedChunkIdsPlugin");
|
455 | new NamedChunkIdsPlugin().apply(compiler);
|
456 | break;
|
457 | }
|
458 | case "deterministic": {
|
459 | const DeterministicChunkIdsPlugin = require("./ids/DeterministicChunkIdsPlugin");
|
460 | new DeterministicChunkIdsPlugin().apply(compiler);
|
461 | break;
|
462 | }
|
463 | case "size": {
|
464 |
|
465 | const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin");
|
466 | new OccurrenceChunkIdsPlugin({
|
467 | prioritiseInitial: true
|
468 | }).apply(compiler);
|
469 | break;
|
470 | }
|
471 | case "total-size": {
|
472 |
|
473 | const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin");
|
474 | new OccurrenceChunkIdsPlugin({
|
475 | prioritiseInitial: false
|
476 | }).apply(compiler);
|
477 | break;
|
478 | }
|
479 | default:
|
480 | throw new Error(
|
481 | `webpack bug: chunkIds: ${chunkIds} is not implemented`
|
482 | );
|
483 | }
|
484 | }
|
485 | if (options.optimization.nodeEnv) {
|
486 | const DefinePlugin = require("./DefinePlugin");
|
487 | new DefinePlugin({
|
488 | "process.env.NODE_ENV": JSON.stringify(options.optimization.nodeEnv)
|
489 | }).apply(compiler);
|
490 | }
|
491 | if (options.optimization.minimize) {
|
492 | for (const minimizer of options.optimization.minimizer) {
|
493 | if (typeof minimizer === "function") {
|
494 | minimizer.call(compiler, compiler);
|
495 | } else if (minimizer !== "...") {
|
496 | minimizer.apply(compiler);
|
497 | }
|
498 | }
|
499 | }
|
500 |
|
501 | if (options.performance) {
|
502 | const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");
|
503 | new SizeLimitsPlugin(options.performance).apply(compiler);
|
504 | }
|
505 |
|
506 | new TemplatedPathPlugin().apply(compiler);
|
507 |
|
508 | new RecordIdsPlugin({
|
509 | portableIds: options.optimization.portableRecords
|
510 | }).apply(compiler);
|
511 |
|
512 | new WarnCaseSensitiveModulesPlugin().apply(compiler);
|
513 |
|
514 | const AddManagedPathsPlugin = require("./cache/AddManagedPathsPlugin");
|
515 | new AddManagedPathsPlugin(
|
516 | options.snapshot.managedPaths,
|
517 | options.snapshot.immutablePaths
|
518 | ).apply(compiler);
|
519 |
|
520 | if (options.cache && typeof options.cache === "object") {
|
521 | const cacheOptions = options.cache;
|
522 | switch (cacheOptions.type) {
|
523 | case "memory": {
|
524 | if (isFinite(cacheOptions.maxGenerations)) {
|
525 |
|
526 | const MemoryWithGcCachePlugin = require("./cache/MemoryWithGcCachePlugin");
|
527 | new MemoryWithGcCachePlugin({
|
528 | maxGenerations: cacheOptions.maxGenerations
|
529 | }).apply(compiler);
|
530 | } else {
|
531 |
|
532 | const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
|
533 | new MemoryCachePlugin().apply(compiler);
|
534 | }
|
535 | break;
|
536 | }
|
537 | case "filesystem": {
|
538 | const AddBuildDependenciesPlugin = require("./cache/AddBuildDependenciesPlugin");
|
539 | for (const key in cacheOptions.buildDependencies) {
|
540 | const list = cacheOptions.buildDependencies[key];
|
541 | new AddBuildDependenciesPlugin(list).apply(compiler);
|
542 | }
|
543 | if (!isFinite(cacheOptions.maxMemoryGenerations)) {
|
544 |
|
545 | const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
|
546 | new MemoryCachePlugin().apply(compiler);
|
547 | } else if (cacheOptions.maxMemoryGenerations !== 0) {
|
548 |
|
549 | const MemoryWithGcCachePlugin = require("./cache/MemoryWithGcCachePlugin");
|
550 | new MemoryWithGcCachePlugin({
|
551 | maxGenerations: cacheOptions.maxMemoryGenerations
|
552 | }).apply(compiler);
|
553 | }
|
554 | switch (cacheOptions.store) {
|
555 | case "pack": {
|
556 | const IdleFileCachePlugin = require("./cache/IdleFileCachePlugin");
|
557 | const PackFileCacheStrategy = require("./cache/PackFileCacheStrategy");
|
558 | new IdleFileCachePlugin(
|
559 | new PackFileCacheStrategy({
|
560 | compiler,
|
561 | fs: compiler.intermediateFileSystem,
|
562 | context: options.context,
|
563 | cacheLocation: cacheOptions.cacheLocation,
|
564 | version: cacheOptions.version,
|
565 | logger: compiler.getInfrastructureLogger(
|
566 | "webpack.cache.PackFileCacheStrategy"
|
567 | ),
|
568 | snapshot: options.snapshot,
|
569 | maxAge: cacheOptions.maxAge
|
570 | }),
|
571 | cacheOptions.idleTimeout,
|
572 | cacheOptions.idleTimeoutForInitialStore
|
573 | ).apply(compiler);
|
574 | break;
|
575 | }
|
576 | default:
|
577 | throw new Error("Unhandled value for cache.store");
|
578 | }
|
579 | break;
|
580 | }
|
581 | default:
|
582 |
|
583 | throw new Error(`Unknown cache type ${cacheOptions.type}`);
|
584 | }
|
585 | }
|
586 | new ResolverCachePlugin().apply(compiler);
|
587 |
|
588 | if (options.ignoreWarnings && options.ignoreWarnings.length > 0) {
|
589 | const IgnoreWarningsPlugin = require("./IgnoreWarningsPlugin");
|
590 | new IgnoreWarningsPlugin(options.ignoreWarnings).apply(compiler);
|
591 | }
|
592 |
|
593 | compiler.hooks.afterPlugins.call(compiler);
|
594 | if (!compiler.inputFileSystem) {
|
595 | throw new Error("No input filesystem provided");
|
596 | }
|
597 | compiler.resolverFactory.hooks.resolveOptions
|
598 | .for("normal")
|
599 | .tap("WebpackOptionsApply", resolveOptions => {
|
600 | resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
601 | resolveOptions.fileSystem = compiler.inputFileSystem;
|
602 | return resolveOptions;
|
603 | });
|
604 | compiler.resolverFactory.hooks.resolveOptions
|
605 | .for("context")
|
606 | .tap("WebpackOptionsApply", resolveOptions => {
|
607 | resolveOptions = cleverMerge(options.resolve, resolveOptions);
|
608 | resolveOptions.fileSystem = compiler.inputFileSystem;
|
609 | resolveOptions.resolveToContext = true;
|
610 | return resolveOptions;
|
611 | });
|
612 | compiler.resolverFactory.hooks.resolveOptions
|
613 | .for("loader")
|
614 | .tap("WebpackOptionsApply", resolveOptions => {
|
615 | resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
|
616 | resolveOptions.fileSystem = compiler.inputFileSystem;
|
617 | return resolveOptions;
|
618 | });
|
619 | compiler.hooks.afterResolvers.call(compiler);
|
620 | return options;
|
621 | }
|
622 | }
|
623 |
|
624 | module.exports = WebpackOptionsApply;
|