UNPKG

23.5 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("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 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({
300 enableExecuteModule: options.experiments.executeModule
301 }).apply(compiler);
302 if (options.node !== false) {
303 const NodeStuffPlugin = require("./NodeStuffPlugin");
304 new NodeStuffPlugin(options.node).apply(compiler);
305 }
306 new APIPlugin().apply(compiler);
307 new ExportsInfoApiPlugin().apply(compiler);
308 new WebpackIsIncludedPlugin().apply(compiler);
309 new ConstPlugin().apply(compiler);
310 new UseStrictPlugin().apply(compiler);
311 new RequireIncludePlugin().apply(compiler);
312 new RequireEnsurePlugin().apply(compiler);
313 new RequireContextPlugin().apply(compiler);
314 new ImportPlugin().apply(compiler);
315 new SystemPlugin().apply(compiler);
316 new ImportMetaPlugin().apply(compiler);
317 new URLPlugin().apply(compiler);
318 new WorkerPlugin(
319 options.output.workerChunkLoading,
320 options.output.workerWasmLoading
321 ).apply(compiler);
322
323 new DefaultStatsFactoryPlugin().apply(compiler);
324 new DefaultStatsPresetPlugin().apply(compiler);
325 new DefaultStatsPrinterPlugin().apply(compiler);
326
327 new JavascriptMetaInfoPlugin().apply(compiler);
328
329 if (typeof options.mode !== "string") {
330 const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");
331 new WarnNoModeSetPlugin().apply(compiler);
332 }
333
334 const EnsureChunkConditionsPlugin = require("./optimize/EnsureChunkConditionsPlugin");
335 new EnsureChunkConditionsPlugin().apply(compiler);
336 if (options.optimization.removeAvailableModules) {
337 const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
338 new RemoveParentModulesPlugin().apply(compiler);
339 }
340 if (options.optimization.removeEmptyChunks) {
341 const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
342 new RemoveEmptyChunksPlugin().apply(compiler);
343 }
344 if (options.optimization.mergeDuplicateChunks) {
345 const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
346 new MergeDuplicateChunksPlugin().apply(compiler);
347 }
348 if (options.optimization.flagIncludedChunks) {
349 const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
350 new FlagIncludedChunksPlugin().apply(compiler);
351 }
352 if (options.optimization.sideEffects) {
353 const SideEffectsFlagPlugin = require("./optimize/SideEffectsFlagPlugin");
354 new SideEffectsFlagPlugin(
355 options.optimization.sideEffects === true
356 ).apply(compiler);
357 }
358 if (options.optimization.providedExports) {
359 const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
360 new FlagDependencyExportsPlugin().apply(compiler);
361 }
362 if (options.optimization.usedExports) {
363 const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
364 new FlagDependencyUsagePlugin(
365 options.optimization.usedExports === "global"
366 ).apply(compiler);
367 }
368 if (options.optimization.innerGraph) {
369 const InnerGraphPlugin = require("./optimize/InnerGraphPlugin");
370 new InnerGraphPlugin().apply(compiler);
371 }
372 if (options.optimization.mangleExports) {
373 const MangleExportsPlugin = require("./optimize/MangleExportsPlugin");
374 new MangleExportsPlugin(
375 options.optimization.mangleExports !== "size"
376 ).apply(compiler);
377 }
378 if (options.optimization.concatenateModules) {
379 const ModuleConcatenationPlugin = require("./optimize/ModuleConcatenationPlugin");
380 new ModuleConcatenationPlugin().apply(compiler);
381 }
382 if (options.optimization.splitChunks) {
383 const SplitChunksPlugin = require("./optimize/SplitChunksPlugin");
384 new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
385 }
386 if (options.optimization.runtimeChunk) {
387 const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
388 new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
389 }
390 if (!options.optimization.emitOnErrors) {
391 const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
392 new NoEmitOnErrorsPlugin().apply(compiler);
393 }
394 if (options.optimization.realContentHash) {
395 const RealContentHashPlugin = require("./optimize/RealContentHashPlugin");
396 new RealContentHashPlugin({
397 hashFunction: options.output.hashFunction,
398 hashDigest: options.output.hashDigest
399 }).apply(compiler);
400 }
401 if (options.optimization.checkWasmTypes) {
402 const WasmFinalizeExportsPlugin = require("./wasm-sync/WasmFinalizeExportsPlugin");
403 new WasmFinalizeExportsPlugin().apply(compiler);
404 }
405 const moduleIds = options.optimization.moduleIds;
406 if (moduleIds) {
407 switch (moduleIds) {
408 case "natural": {
409 const NaturalModuleIdsPlugin = require("./ids/NaturalModuleIdsPlugin");
410 new NaturalModuleIdsPlugin().apply(compiler);
411 break;
412 }
413 case "named": {
414 const NamedModuleIdsPlugin = require("./ids/NamedModuleIdsPlugin");
415 new NamedModuleIdsPlugin().apply(compiler);
416 break;
417 }
418 case "hashed": {
419 const WarnDeprecatedOptionPlugin = require("./WarnDeprecatedOptionPlugin");
420 const HashedModuleIdsPlugin = require("./ids/HashedModuleIdsPlugin");
421 new WarnDeprecatedOptionPlugin(
422 "optimization.moduleIds",
423 "hashed",
424 "deterministic"
425 ).apply(compiler);
426 new HashedModuleIdsPlugin().apply(compiler);
427 break;
428 }
429 case "deterministic": {
430 const DeterministicModuleIdsPlugin = require("./ids/DeterministicModuleIdsPlugin");
431 new DeterministicModuleIdsPlugin().apply(compiler);
432 break;
433 }
434 case "size": {
435 const OccurrenceModuleIdsPlugin = require("./ids/OccurrenceModuleIdsPlugin");
436 new OccurrenceModuleIdsPlugin({
437 prioritiseInitial: true
438 }).apply(compiler);
439 break;
440 }
441 default:
442 throw new Error(
443 `webpack bug: moduleIds: ${moduleIds} is not implemented`
444 );
445 }
446 }
447 const chunkIds = options.optimization.chunkIds;
448 if (chunkIds) {
449 switch (chunkIds) {
450 case "natural": {
451 const NaturalChunkIdsPlugin = require("./ids/NaturalChunkIdsPlugin");
452 new NaturalChunkIdsPlugin().apply(compiler);
453 break;
454 }
455 case "named": {
456 const NamedChunkIdsPlugin = require("./ids/NamedChunkIdsPlugin");
457 new NamedChunkIdsPlugin().apply(compiler);
458 break;
459 }
460 case "deterministic": {
461 const DeterministicChunkIdsPlugin = require("./ids/DeterministicChunkIdsPlugin");
462 new DeterministicChunkIdsPlugin().apply(compiler);
463 break;
464 }
465 case "size": {
466 //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
467 const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin");
468 new OccurrenceChunkIdsPlugin({
469 prioritiseInitial: true
470 }).apply(compiler);
471 break;
472 }
473 case "total-size": {
474 //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
475 const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin");
476 new OccurrenceChunkIdsPlugin({
477 prioritiseInitial: false
478 }).apply(compiler);
479 break;
480 }
481 default:
482 throw new Error(
483 `webpack bug: chunkIds: ${chunkIds} is not implemented`
484 );
485 }
486 }
487 if (options.optimization.nodeEnv) {
488 const DefinePlugin = require("./DefinePlugin");
489 new DefinePlugin({
490 "process.env.NODE_ENV": JSON.stringify(options.optimization.nodeEnv)
491 }).apply(compiler);
492 }
493 if (options.optimization.minimize) {
494 for (const minimizer of options.optimization.minimizer) {
495 if (typeof minimizer === "function") {
496 minimizer.call(compiler, compiler);
497 } else if (minimizer !== "...") {
498 minimizer.apply(compiler);
499 }
500 }
501 }
502
503 if (options.performance) {
504 const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");
505 new SizeLimitsPlugin(options.performance).apply(compiler);
506 }
507
508 new TemplatedPathPlugin().apply(compiler);
509
510 new RecordIdsPlugin({
511 portableIds: options.optimization.portableRecords
512 }).apply(compiler);
513
514 new WarnCaseSensitiveModulesPlugin().apply(compiler);
515
516 const AddManagedPathsPlugin = require("./cache/AddManagedPathsPlugin");
517 new AddManagedPathsPlugin(
518 options.snapshot.managedPaths,
519 options.snapshot.immutablePaths
520 ).apply(compiler);
521
522 if (options.cache && typeof options.cache === "object") {
523 const cacheOptions = options.cache;
524 switch (cacheOptions.type) {
525 case "memory": {
526 if (isFinite(cacheOptions.maxGenerations)) {
527 //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
528 const MemoryWithGcCachePlugin = require("./cache/MemoryWithGcCachePlugin");
529 new MemoryWithGcCachePlugin({
530 maxGenerations: cacheOptions.maxGenerations
531 }).apply(compiler);
532 } else {
533 //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
534 const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
535 new MemoryCachePlugin().apply(compiler);
536 }
537 break;
538 }
539 case "filesystem": {
540 const AddBuildDependenciesPlugin = require("./cache/AddBuildDependenciesPlugin");
541 for (const key in cacheOptions.buildDependencies) {
542 const list = cacheOptions.buildDependencies[key];
543 new AddBuildDependenciesPlugin(list).apply(compiler);
544 }
545 if (!isFinite(cacheOptions.maxMemoryGenerations)) {
546 //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
547 const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
548 new MemoryCachePlugin().apply(compiler);
549 } else if (cacheOptions.maxMemoryGenerations !== 0) {
550 //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
551 const MemoryWithGcCachePlugin = require("./cache/MemoryWithGcCachePlugin");
552 new MemoryWithGcCachePlugin({
553 maxGenerations: cacheOptions.maxMemoryGenerations
554 }).apply(compiler);
555 }
556 switch (cacheOptions.store) {
557 case "pack": {
558 const IdleFileCachePlugin = require("./cache/IdleFileCachePlugin");
559 const PackFileCacheStrategy = require("./cache/PackFileCacheStrategy");
560 new IdleFileCachePlugin(
561 new PackFileCacheStrategy({
562 compiler,
563 fs: compiler.intermediateFileSystem,
564 context: options.context,
565 cacheLocation: cacheOptions.cacheLocation,
566 version: cacheOptions.version,
567 logger: compiler.getInfrastructureLogger(
568 "webpack.cache.PackFileCacheStrategy"
569 ),
570 snapshot: options.snapshot,
571 maxAge: cacheOptions.maxAge
572 }),
573 cacheOptions.idleTimeout,
574 cacheOptions.idleTimeoutForInitialStore
575 ).apply(compiler);
576 break;
577 }
578 default:
579 throw new Error("Unhandled value for cache.store");
580 }
581 break;
582 }
583 default:
584 // @ts-expect-error Property 'type' does not exist on type 'never'. ts(2339)
585 throw new Error(`Unknown cache type ${cacheOptions.type}`);
586 }
587 }
588 new ResolverCachePlugin().apply(compiler);
589
590 if (options.ignoreWarnings && options.ignoreWarnings.length > 0) {
591 const IgnoreWarningsPlugin = require("./IgnoreWarningsPlugin");
592 new IgnoreWarningsPlugin(options.ignoreWarnings).apply(compiler);
593 }
594
595 compiler.hooks.afterPlugins.call(compiler);
596 if (!compiler.inputFileSystem) {
597 throw new Error("No input filesystem provided");
598 }
599 compiler.resolverFactory.hooks.resolveOptions
600 .for("normal")
601 .tap("WebpackOptionsApply", resolveOptions => {
602 resolveOptions = cleverMerge(options.resolve, resolveOptions);
603 resolveOptions.fileSystem = compiler.inputFileSystem;
604 return resolveOptions;
605 });
606 compiler.resolverFactory.hooks.resolveOptions
607 .for("context")
608 .tap("WebpackOptionsApply", resolveOptions => {
609 resolveOptions = cleverMerge(options.resolve, resolveOptions);
610 resolveOptions.fileSystem = compiler.inputFileSystem;
611 resolveOptions.resolveToContext = true;
612 return resolveOptions;
613 });
614 compiler.resolverFactory.hooks.resolveOptions
615 .for("loader")
616 .tap("WebpackOptionsApply", resolveOptions => {
617 resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
618 resolveOptions.fileSystem = compiler.inputFileSystem;
619 return resolveOptions;
620 });
621 compiler.hooks.afterResolvers.call(compiler);
622 return options;
623 }
624}
625
626module.exports = WebpackOptionsApply;