UNPKG

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