webpack 5.105.4 → 5.106.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 (123) hide show
  1. package/README.md +3 -6
  2. package/lib/BannerPlugin.js +13 -13
  3. package/lib/Chunk.js +25 -0
  4. package/lib/ChunkGraph.js +8 -4
  5. package/lib/CleanPlugin.js +23 -20
  6. package/lib/CompatibilityPlugin.js +1 -1
  7. package/lib/Compilation.js +34 -11
  8. package/lib/Compiler.js +59 -1
  9. package/lib/CssModule.js +17 -2
  10. package/lib/Dependency.js +1 -1
  11. package/lib/DllPlugin.js +17 -17
  12. package/lib/DllReferencePlugin.js +20 -18
  13. package/lib/DotenvPlugin.js +29 -27
  14. package/lib/ExternalModule.js +39 -6
  15. package/lib/FileSystemInfo.js +3 -1
  16. package/lib/IgnorePlugin.js +12 -11
  17. package/lib/LoaderOptionsPlugin.js +17 -15
  18. package/lib/ManifestPlugin.js +27 -25
  19. package/lib/Module.js +69 -4
  20. package/lib/ModuleGraph.js +3 -0
  21. package/lib/ModuleParseError.js +1 -1
  22. package/lib/ModuleTypeConstants.js +1 -1
  23. package/lib/NormalModule.js +7 -3
  24. package/lib/NormalModuleFactory.js +20 -1
  25. package/lib/ProgressPlugin.js +39 -29
  26. package/lib/RuntimeGlobals.js +6 -0
  27. package/lib/RuntimeTemplate.js +1 -1
  28. package/lib/SourceMapDevToolPlugin.js +13 -11
  29. package/lib/TemplatedPathPlugin.js +4 -3
  30. package/lib/WatchIgnorePlugin.js +15 -13
  31. package/lib/WebpackOptionsApply.js +4 -4
  32. package/lib/asset/AssetModulesPlugin.js +50 -29
  33. package/lib/cli.js +3 -1
  34. package/lib/config/defaults.js +27 -13
  35. package/lib/config/normalization.js +3 -2
  36. package/lib/container/ContainerPlugin.js +46 -42
  37. package/lib/container/ContainerReferencePlugin.js +42 -26
  38. package/lib/container/FallbackModule.js +1 -1
  39. package/lib/container/ModuleFederationPlugin.js +17 -13
  40. package/lib/css/CssGenerator.js +306 -192
  41. package/lib/css/CssInjectStyleRuntimeModule.js +179 -0
  42. package/lib/css/CssLoadingRuntimeModule.js +1 -4
  43. package/lib/css/CssModulesPlugin.js +197 -98
  44. package/lib/css/CssParser.js +231 -134
  45. package/lib/css/walkCssTokens.js +115 -12
  46. package/lib/debug/ProfilingPlugin.js +16 -13
  47. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +20 -15
  48. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -3
  49. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -2
  50. package/lib/dependencies/CommonJsExportsDependency.js +1 -1
  51. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  52. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  53. package/lib/dependencies/CommonJsImportsParserPlugin.js +63 -2
  54. package/lib/dependencies/CommonJsRequireContextDependency.js +21 -0
  55. package/lib/dependencies/CommonJsRequireDependency.js +42 -1
  56. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
  57. package/lib/dependencies/ContextElementDependency.js +1 -1
  58. package/lib/dependencies/CssIcssExportDependency.js +210 -87
  59. package/lib/dependencies/CssIcssImportDependency.js +13 -70
  60. package/lib/dependencies/CssIcssSymbolDependency.js +19 -30
  61. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +13 -2
  62. package/lib/dependencies/HarmonyExportExpressionDependency.js +28 -2
  63. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -3
  64. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  65. package/lib/dependencies/HarmonyImportDependency.js +21 -8
  66. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +4 -1
  67. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportSpecifierDependency.js +13 -2
  69. package/lib/dependencies/ImportContextDependency.js +1 -1
  70. package/lib/dependencies/ImportDependency.js +16 -2
  71. package/lib/dependencies/ImportMetaPlugin.js +39 -29
  72. package/lib/dependencies/ImportParserPlugin.js +4 -5
  73. package/lib/dependencies/ImportPhase.js +65 -22
  74. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
  75. package/lib/esm/ModuleChunkFormatPlugin.js +1 -4
  76. package/lib/ids/HashedModuleIdsPlugin.js +21 -23
  77. package/lib/ids/OccurrenceChunkIdsPlugin.js +15 -11
  78. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -11
  79. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -4
  80. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -4
  81. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -2
  82. package/lib/javascript/JavascriptModulesPlugin.js +38 -12
  83. package/lib/javascript/JavascriptParser.js +5 -3
  84. package/lib/json/JsonModulesPlugin.js +28 -21
  85. package/lib/library/AssignLibraryPlugin.js +1 -1
  86. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  87. package/lib/library/ModuleLibraryPlugin.js +35 -13
  88. package/lib/library/SystemLibraryPlugin.js +1 -1
  89. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +22 -0
  90. package/lib/optimize/AggressiveSplittingPlugin.js +18 -31
  91. package/lib/optimize/ConcatenatedModule.js +4 -3
  92. package/lib/optimize/InnerGraphPlugin.js +11 -5
  93. package/lib/optimize/LimitChunkCountPlugin.js +22 -18
  94. package/lib/optimize/MergeDuplicateChunksPlugin.js +15 -12
  95. package/lib/optimize/MinChunkSizePlugin.js +20 -16
  96. package/lib/optimize/RemoveEmptyChunksPlugin.js +0 -1
  97. package/lib/rules/RuleSetCompiler.js +1 -0
  98. package/lib/schemes/HttpUriPlugin.js +20 -11
  99. package/lib/schemes/VirtualUrlPlugin.js +77 -30
  100. package/lib/serialization/FileMiddleware.js +7 -7
  101. package/lib/sharing/ConsumeSharedPlugin.js +32 -25
  102. package/lib/sharing/ProvideSharedPlugin.js +29 -25
  103. package/lib/util/{propertyName.js → property.js} +26 -1
  104. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +148 -0
  105. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +54 -0
  106. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +105 -0
  107. package/lib/wasm-async/AsyncWebAssemblyParser.js +30 -6
  108. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +26 -2
  109. package/lib/web/FetchCompileAsyncWasmPlugin.js +23 -0
  110. package/lib/web/JsonpTemplatePlugin.js +1 -0
  111. package/lib/webpack.js +34 -4
  112. package/package.json +18 -16
  113. package/schemas/WebpackOptions.check.js +1 -1
  114. package/schemas/WebpackOptions.json +82 -22
  115. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  116. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  117. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  118. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +1 -1
  119. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -1
  120. package/schemas/plugins/schemes/VirtualUrlPlugin.json +8 -0
  121. package/types.d.ts +511 -114
  122. package/lib/util/create-schema-validation.js +0 -41
  123. package/lib/util/propertyAccess.js +0 -30
package/lib/DllPlugin.js CHANGED
@@ -8,22 +8,12 @@
8
8
  const DllEntryPlugin = require("./DllEntryPlugin");
9
9
  const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
10
10
  const LibManifestPlugin = require("./LibManifestPlugin");
11
- const createSchemaValidation = require("./util/create-schema-validation");
12
11
 
13
12
  /** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
14
13
  /** @typedef {import("./Compiler")} Compiler */
15
14
  /** @typedef {import("./DllEntryPlugin").Entries} Entries */
16
15
  /** @typedef {import("./DllEntryPlugin").Options} Options */
17
16
 
18
- const validate = createSchemaValidation(
19
- require("../schemas/plugins/DllPlugin.check"),
20
- () => require("../schemas/plugins/DllPlugin.json"),
21
- {
22
- name: "Dll Plugin",
23
- baseDataPath: "options"
24
- }
25
- );
26
-
27
17
  const PLUGIN_NAME = "DllPlugin";
28
18
 
29
19
  class DllPlugin {
@@ -31,11 +21,8 @@ class DllPlugin {
31
21
  * @param {DllPluginOptions} options options object
32
22
  */
33
23
  constructor(options) {
34
- validate(options);
35
- this.options = {
36
- ...options,
37
- entryOnly: options.entryOnly !== false
38
- };
24
+ /** @type {DllPluginOptions} */
25
+ this.options = options;
39
26
  }
40
27
 
41
28
  /**
@@ -44,6 +31,19 @@ class DllPlugin {
44
31
  * @returns {void}
45
32
  */
46
33
  apply(compiler) {
34
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
35
+ compiler.validate(
36
+ () => require("../schemas/plugins/DllPlugin.json"),
37
+ this.options,
38
+ {
39
+ name: "Dll Plugin",
40
+ baseDataPath: "options"
41
+ },
42
+ (options) => require("../schemas/plugins/DllPlugin.check")(options)
43
+ );
44
+ });
45
+
46
+ const entryOnly = this.options.entryOnly !== false;
47
47
  compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => {
48
48
  if (typeof entry !== "function") {
49
49
  for (const name of Object.keys(entry)) {
@@ -63,8 +63,8 @@ class DllPlugin {
63
63
  }
64
64
  return true;
65
65
  });
66
- new LibManifestPlugin(this.options).apply(compiler);
67
- if (!this.options.entryOnly) {
66
+ new LibManifestPlugin({ ...this.options, entryOnly }).apply(compiler);
67
+ if (!entryOnly) {
68
68
  new FlagAllModulesAsUsedPlugin(PLUGIN_NAME).apply(compiler);
69
69
  }
70
70
  }
@@ -10,7 +10,6 @@ const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
10
10
  const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
11
11
  const WebpackError = require("./WebpackError");
12
12
  const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
13
- const createSchemaValidation = require("./util/create-schema-validation");
14
13
  const makePathsRelative = require("./util/identifier").makePathsRelative;
15
14
 
16
15
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
@@ -21,15 +20,6 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
21
20
  /** @typedef {import("./Compiler").CompilationParams} CompilationParams */
22
21
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
23
22
 
24
- const validate = createSchemaValidation(
25
- require("../schemas/plugins/DllReferencePlugin.check"),
26
- () => require("../schemas/plugins/DllReferencePlugin.json"),
27
- {
28
- name: "Dll Reference Plugin",
29
- baseDataPath: "options"
30
- }
31
- );
32
-
33
23
  /** @typedef {{ path: string, data: DllReferencePluginOptionsManifest | undefined, error: Error | undefined }} CompilationDataItem */
34
24
 
35
25
  const PLUGIN_NAME = "DllReferencePlugin";
@@ -39,10 +29,7 @@ class DllReferencePlugin {
39
29
  * @param {DllReferencePluginOptions} options options object
40
30
  */
41
31
  constructor(options) {
42
- validate(options);
43
32
  this.options = options;
44
- /** @type {WeakMap<CompilationParams, CompilationDataItem>} */
45
- this._compilationData = new WeakMap();
46
33
  }
47
34
 
48
35
  /**
@@ -51,6 +38,18 @@ class DllReferencePlugin {
51
38
  * @returns {void}
52
39
  */
53
40
  apply(compiler) {
41
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
42
+ compiler.validate(
43
+ () => require("../schemas/plugins/DllReferencePlugin.json"),
44
+ this.options,
45
+ {
46
+ name: "Dll Reference Plugin",
47
+ baseDataPath: "options"
48
+ },
49
+ (options) =>
50
+ require("../schemas/plugins/DllReferencePlugin.check")(options)
51
+ );
52
+ });
54
53
  compiler.hooks.compilation.tap(
55
54
  PLUGIN_NAME,
56
55
  (compilation, { normalModuleFactory }) => {
@@ -61,6 +60,9 @@ class DllReferencePlugin {
61
60
  }
62
61
  );
63
62
 
63
+ /** @type {WeakMap<CompilationParams, CompilationDataItem>} */
64
+ const compilationData = new WeakMap();
65
+
64
66
  compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
65
67
  if ("manifest" in this.options) {
66
68
  const manifest = this.options.manifest;
@@ -93,7 +95,7 @@ class DllReferencePlugin {
93
95
  /** @type {Error} */ (parseErr).message
94
96
  );
95
97
  }
96
- this._compilationData.set(params, data);
98
+ compilationData.set(params, data);
97
99
  return callback();
98
100
  });
99
101
  return;
@@ -114,7 +116,7 @@ class DllReferencePlugin {
114
116
  if (typeof manifestParameter === "string") {
115
117
  const data =
116
118
  /** @type {CompilationDataItem} */
117
- (this._compilationData.get(params));
119
+ (compilationData.get(params));
118
120
  // If there was an error parsing the manifest
119
121
  // file, exit now because the error will be added
120
122
  // as a compilation error in the "compilation" hook.
@@ -156,9 +158,9 @@ class DllReferencePlugin {
156
158
  if ("manifest" in this.options) {
157
159
  const manifest = this.options.manifest;
158
160
  if (typeof manifest === "string") {
159
- const data = /** @type {CompilationDataItem} */ (
160
- this._compilationData.get(params)
161
- );
161
+ const data =
162
+ /** @type {CompilationDataItem} */
163
+ (compilationData.get(params));
162
164
  // If there was an error parsing the manifest file, add the
163
165
  // error as a compilation error to make the compilation fail.
164
166
  if (data.error) {
@@ -6,7 +6,6 @@
6
6
  "use strict";
7
7
 
8
8
  const FileSystemInfo = require("./FileSystemInfo");
9
- const createSchemaValidation = require("./util/create-schema-validation");
10
9
  const { join } = require("./util/fs");
11
10
 
12
11
  /** @typedef {import("../declarations/WebpackOptions").DotenvPluginOptions} DotenvPluginOptions */
@@ -18,11 +17,12 @@ const { join } = require("./util/fs");
18
17
  /** @typedef {Exclude<DotenvPluginOptions["prefix"], string | undefined>} Prefix */
19
18
  /** @typedef {Record<string, string>} Env */
20
19
 
21
- /** @type {DotenvPluginOptions} */
22
- const DEFAULT_OPTIONS = {
23
- prefix: "WEBPACK_",
24
- template: [".env", ".env.local", ".env.[mode]", ".env.[mode].local"]
25
- };
20
+ const DEFAULT_TEMPLATE = [
21
+ ".env",
22
+ ".env.local",
23
+ ".env.[mode]",
24
+ ".env.[mode].local"
25
+ ];
26
26
 
27
27
  // Regex for parsing .env files
28
28
  // ported from https://github.com/motdotla/dotenv/blob/master/lib/main.js#L49
@@ -31,22 +31,6 @@ const LINE =
31
31
 
32
32
  const PLUGIN_NAME = "DotenvPlugin";
33
33
 
34
- const validate = createSchemaValidation(
35
- undefined,
36
- () => {
37
- const { definitions } = require("../schemas/WebpackOptions.json");
38
-
39
- return {
40
- definitions,
41
- oneOf: [{ $ref: "#/definitions/DotenvPluginOptions" }]
42
- };
43
- },
44
- {
45
- name: "Dotenv Plugin",
46
- baseDataPath: "options"
47
- }
48
- );
49
-
50
34
  /**
51
35
  * Parse .env file content
52
36
  * ported from https://github.com/motdotla/dotenv/blob/master/lib/main.js#L49
@@ -233,8 +217,8 @@ class DotenvPlugin {
233
217
  * @param {DotenvPluginOptions=} options options object
234
218
  */
235
219
  constructor(options = {}) {
236
- validate(options);
237
- this.options = { ...DEFAULT_OPTIONS, ...options };
220
+ /** @type {DotenvPluginOptions} */
221
+ this.options = options;
238
222
  }
239
223
 
240
224
  /**
@@ -242,6 +226,23 @@ class DotenvPlugin {
242
226
  * @returns {void}
243
227
  */
244
228
  apply(compiler) {
229
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
230
+ compiler.validate(
231
+ () => {
232
+ const { definitions } = require("../schemas/WebpackOptions.json");
233
+
234
+ return {
235
+ definitions,
236
+ oneOf: [{ $ref: "#/definitions/DotenvPluginOptions" }]
237
+ };
238
+ },
239
+ this.options,
240
+ {
241
+ name: "Dotenv Plugin",
242
+ baseDataPath: "options"
243
+ }
244
+ );
245
+ });
245
246
  const definePlugin = new compiler.webpack.DefinePlugin({});
246
247
  const prefixes = Array.isArray(this.options.prefix)
247
248
  ? this.options.prefix
@@ -258,7 +259,9 @@ class DotenvPlugin {
258
259
  let snapshot;
259
260
 
260
261
  const cache = compiler.getCache(PLUGIN_NAME);
261
- const identifier = JSON.stringify(this.options.template);
262
+ const identifier = JSON.stringify(
263
+ this.options.template || DEFAULT_TEMPLATE
264
+ );
262
265
  const itemCache = cache.getItemCache(identifier, null);
263
266
 
264
267
  compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
@@ -295,8 +298,7 @@ class DotenvPlugin {
295
298
  return [];
296
299
  }
297
300
 
298
- const { template } = /** @type {DotenvPluginOptions} */ (this.options);
299
- const templates = template || [];
301
+ const templates = this.options.template || DEFAULT_TEMPLATE;
300
302
 
301
303
  return templates
302
304
  .map((pattern) => pattern.replace(/\[mode\]/g, mode || "development"))
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { SyncBailHook } = require("tapable");
8
9
  const { OriginalSource, RawSource } = require("webpack-sources");
9
10
  const ConcatenationScope = require("./ConcatenationScope");
10
11
  const EnvironmentNotSupportAsyncWarning = require("./EnvironmentNotSupportAsyncWarning");
@@ -25,7 +26,7 @@ const StaticExportsDependency = require("./dependencies/StaticExportsDependency"
25
26
  const createHash = require("./util/createHash");
26
27
  const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
27
28
  const makeSerializable = require("./util/makeSerializable");
28
- const propertyAccess = require("./util/propertyAccess");
29
+ const { propertyAccess } = require("./util/property");
29
30
  const { register } = require("./util/serialization");
30
31
 
31
32
  /** @typedef {import("webpack-sources").Source} Source */
@@ -629,6 +630,14 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
629
630
  /** @typedef {Record<string, string | string[]>} RequestRecord */
630
631
  /** @typedef {string | string[] | RequestRecord} ExternalModuleRequest */
631
632
 
633
+ /**
634
+ * @typedef {object} ExternalModuleHooks
635
+ * @property {SyncBailHook<[Chunk, Compilation], boolean>} chunkCondition
636
+ */
637
+
638
+ /** @type {WeakMap<Compilation, ExternalModuleHooks>} */
639
+ const compilationHooksMap = new WeakMap();
640
+
632
641
  class ExternalModule extends Module {
633
642
  /**
634
643
  * @param {ExternalModuleRequest} request request
@@ -650,6 +659,21 @@ class ExternalModule extends Module {
650
659
  this.dependencyMeta = dependencyMeta;
651
660
  }
652
661
 
662
+ /**
663
+ * @param {Compilation} compilation the compilation
664
+ * @returns {ExternalModuleHooks} the attached hooks
665
+ */
666
+ static getCompilationHooks(compilation) {
667
+ let hooks = compilationHooksMap.get(compilation);
668
+ if (hooks === undefined) {
669
+ hooks = {
670
+ chunkCondition: new SyncBailHook(["chunk", "compilation"])
671
+ };
672
+ compilationHooksMap.set(compilation, hooks);
673
+ }
674
+ return hooks;
675
+ }
676
+
653
677
  /**
654
678
  * @returns {SourceTypes} types available (do not mutate)
655
679
  */
@@ -679,12 +703,21 @@ class ExternalModule extends Module {
679
703
  /**
680
704
  * @param {Chunk} chunk the chunk which condition should be checked
681
705
  * @param {Compilation} compilation the compilation
682
- * @returns {boolean} true, if the chunk is ok for the module
706
+ * @returns {boolean} true if the module can be placed in the chunk
683
707
  */
684
- chunkCondition(chunk, { chunkGraph }) {
685
- return this.externalType === "css-import"
686
- ? true
687
- : chunkGraph.getNumberOfEntryModules(chunk) > 0;
708
+ chunkCondition(chunk, compilation) {
709
+ const { chunkCondition } = ExternalModule.getCompilationHooks(compilation);
710
+ const condition = chunkCondition.call(chunk, compilation);
711
+ if (condition !== undefined) return condition;
712
+
713
+ const type = this._resolveExternalType(this.externalType);
714
+
715
+ // For `import()` externals, keep them in the initial chunk to avoid loading
716
+ // them asynchronously twice and to improve runtime performance.
717
+ if (["css-import", "module"].includes(type)) {
718
+ return true;
719
+ }
720
+ return compilation.chunkGraph.getNumberOfEntryModules(chunk) > 0;
688
721
  }
689
722
 
690
723
  /**
@@ -1805,7 +1805,9 @@ class FileSystemInfo {
1805
1805
  break;
1806
1806
  }
1807
1807
  case RBDT_RESOLVE_DIRECTORY: {
1808
- resolveDirectory(RBDT_RESOLVE_INITIAL ? path.slice(0, -1) : path);
1808
+ resolveDirectory(
1809
+ type === RBDT_RESOLVE_INITIAL ? path.slice(0, -1) : path
1810
+ );
1809
1811
  break;
1810
1812
  }
1811
1813
  case RBDT_RESOLVE_CJS_FILE: {
@@ -7,22 +7,12 @@
7
7
 
8
8
  const RawModule = require("./RawModule");
9
9
  const EntryDependency = require("./dependencies/EntryDependency");
10
- const createSchemaValidation = require("./util/create-schema-validation");
11
10
 
12
11
  /** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
13
12
  /** @typedef {import("./Compiler")} Compiler */
14
13
  /** @typedef {import("./NormalModuleFactory").ResolveData} ResolveData */
15
14
  /** @typedef {import("./ContextModuleFactory").BeforeContextResolveData} BeforeContextResolveData */
16
15
 
17
- const validate = createSchemaValidation(
18
- require("../schemas/plugins/IgnorePlugin.check"),
19
- () => require("../schemas/plugins/IgnorePlugin.json"),
20
- {
21
- name: "Ignore Plugin",
22
- baseDataPath: "options"
23
- }
24
- );
25
-
26
16
  /** @typedef {(resource: string, context: string) => boolean} CheckResourceFn */
27
17
 
28
18
  const PLUGIN_NAME = "IgnorePlugin";
@@ -32,7 +22,6 @@ class IgnorePlugin {
32
22
  * @param {IgnorePluginOptions} options IgnorePlugin options
33
23
  */
34
24
  constructor(options) {
35
- validate(options);
36
25
  this.options = options;
37
26
  this.checkIgnore = this.checkIgnore.bind(this);
38
27
  }
@@ -74,6 +63,18 @@ class IgnorePlugin {
74
63
  * @returns {void}
75
64
  */
76
65
  apply(compiler) {
66
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
67
+ compiler.validate(
68
+ require("../schemas/plugins/IgnorePlugin.json"),
69
+ this.options,
70
+ {
71
+ name: "Ignore Plugin",
72
+ baseDataPath: "options"
73
+ },
74
+ (options) => require("../schemas/plugins/IgnorePlugin.check")(options)
75
+ );
76
+ });
77
+
77
78
  compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (nmf) => {
78
79
  nmf.hooks.beforeResolve.tap(PLUGIN_NAME, (resolveData) => {
79
80
  const result = this.checkIgnore(resolveData);
@@ -7,7 +7,6 @@
7
7
 
8
8
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
9
9
  const NormalModule = require("./NormalModule");
10
- const createSchemaValidation = require("./util/create-schema-validation");
11
10
 
12
11
  /** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
13
12
  /** @typedef {import("./Compiler")} Compiler */
@@ -18,15 +17,6 @@ const createSchemaValidation = require("./util/create-schema-validation");
18
17
  * @typedef {import("../declarations/LoaderContext").LoaderContext<T>} LoaderContext
19
18
  */
20
19
 
21
- const validate = createSchemaValidation(
22
- require("../schemas/plugins/LoaderOptionsPlugin.check"),
23
- () => require("../schemas/plugins/LoaderOptionsPlugin.json"),
24
- {
25
- name: "Loader Options Plugin",
26
- baseDataPath: "options"
27
- }
28
- );
29
-
30
20
  const PLUGIN_NAME = "LoaderOptionsPlugin";
31
21
 
32
22
  class LoaderOptionsPlugin {
@@ -34,12 +24,12 @@ class LoaderOptionsPlugin {
34
24
  * @param {LoaderOptionsPluginOptions & MatchObject} options options object
35
25
  */
36
26
  constructor(options = {}) {
37
- validate(options);
38
27
  // If no options are set then generate empty options object
39
28
  if (typeof options !== "object") options = {};
40
29
  if (!options.test) {
41
30
  options.test = () => true;
42
31
  }
32
+ /** @type {LoaderOptionsPluginOptions & MatchObject} */
43
33
  this.options = options;
44
34
  }
45
35
 
@@ -49,7 +39,19 @@ class LoaderOptionsPlugin {
49
39
  * @returns {void}
50
40
  */
51
41
  apply(compiler) {
52
- const options = this.options;
42
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
43
+ compiler.validate(
44
+ () => require("../schemas/plugins/LoaderOptionsPlugin.json"),
45
+ this.options,
46
+ {
47
+ name: "Loader Options Plugin",
48
+ baseDataPath: "options"
49
+ },
50
+ (options) =>
51
+ require("../schemas/plugins/LoaderOptionsPlugin.check")(options)
52
+ );
53
+ });
54
+
53
55
  compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
54
56
  NormalModule.getCompilationHooks(compilation).loader.tap(
55
57
  PLUGIN_NAME,
@@ -59,17 +61,17 @@ class LoaderOptionsPlugin {
59
61
  const i = resource.indexOf("?");
60
62
  if (
61
63
  ModuleFilenameHelpers.matchObject(
62
- options,
64
+ this.options,
63
65
  i < 0 ? resource : resource.slice(0, i)
64
66
  )
65
67
  ) {
66
- for (const key of Object.keys(options)) {
68
+ for (const key of Object.keys(this.options)) {
67
69
  if (key === "include" || key === "exclude" || key === "test") {
68
70
  continue;
69
71
  }
70
72
 
71
73
  /** @type {LoaderContext<EXPECTED_ANY> & Record<string, EXPECTED_ANY>} */
72
- (context)[key] = options[key];
74
+ (context)[key] = this.options[key];
73
75
  }
74
76
  }
75
77
  }
@@ -8,7 +8,6 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Compilation = require("./Compilation");
10
10
  const HotUpdateChunk = require("./HotUpdateChunk");
11
- const createSchemaValidation = require("./util/create-schema-validation");
12
11
 
13
12
  /** @typedef {import("./Compiler")} Compiler */
14
13
  /** @typedef {import("./Chunk")} Chunk */
@@ -28,15 +27,6 @@ const createSchemaValidation = require("./util/create-schema-validation");
28
27
 
29
28
  const PLUGIN_NAME = "ManifestPlugin";
30
29
 
31
- const validate = createSchemaValidation(
32
- require("../schemas/plugins/ManifestPlugin.check"),
33
- () => require("../schemas/plugins/ManifestPlugin.json"),
34
- {
35
- name: "ManifestPlugin",
36
- baseDataPath: "options"
37
- }
38
- );
39
-
40
30
  /**
41
31
  * @param {string} filename filename
42
32
  * @returns {string} extname
@@ -51,21 +41,16 @@ const extname = (filename) => {
51
41
  : last;
52
42
  };
53
43
 
44
+ const DEFAULT_PREFIX = "[publicpath]";
45
+ const DEFAULT_FILENAME = "manifest.json";
46
+
54
47
  class ManifestPlugin {
55
48
  /**
56
49
  * @param {ManifestPluginOptions} options options
57
50
  */
58
- constructor(options) {
59
- validate(options);
60
-
61
- /** @type {ManifestPluginOptions & Required<Omit<ManifestPluginOptions, "filter" | "generate">>} */
62
- this.options = {
63
- filename: "manifest.json",
64
- prefix: "[publicpath]",
65
- entrypoints: true,
66
- serialize: (manifest) => JSON.stringify(manifest, null, 2),
67
- ...options
68
- };
51
+ constructor(options = {}) {
52
+ /** @type {ManifestPluginOptions} */
53
+ this.options = options;
69
54
  }
70
55
 
71
56
  /**
@@ -74,6 +59,23 @@ class ManifestPlugin {
74
59
  * @returns {void}
75
60
  */
76
61
  apply(compiler) {
62
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
63
+ compiler.validate(
64
+ () => require("../schemas/plugins/ManifestPlugin.json"),
65
+ this.options,
66
+ {
67
+ name: "ManifestPlugin",
68
+ baseDataPath: "options"
69
+ },
70
+ (options) => require("../schemas/plugins/ManifestPlugin.check")(options)
71
+ );
72
+ });
73
+
74
+ const entrypoints = this.options.entrypoints || true;
75
+ const serialize =
76
+ this.options.serialize ||
77
+ ((manifest) => JSON.stringify(manifest, null, 2));
78
+
77
79
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
78
80
  compilation.hooks.processAssets.tap(
79
81
  {
@@ -122,7 +124,7 @@ class ManifestPlugin {
122
124
  /** @type {ManifestObject} */
123
125
  let manifest = {};
124
126
 
125
- if (this.options.entrypoints) {
127
+ if (entrypoints) {
126
128
  /** @type {ManifestObject["entrypoints"]} */
127
129
  const entrypoints = {};
128
130
 
@@ -178,7 +180,7 @@ class ManifestPlugin {
178
180
  // Fallback for unofficial plugins, just remove hash from filename
179
181
  removeHash(file, asset.info);
180
182
 
181
- const prefix = this.options.prefix.replace(
183
+ const prefix = (this.options.prefix || DEFAULT_PREFIX).replace(
182
184
  /\[publicpath\]/gi,
183
185
  () => (publicPath === "auto" ? "/" : publicPath)
184
186
  );
@@ -229,8 +231,8 @@ class ManifestPlugin {
229
231
  }
230
232
 
231
233
  compilation.emitAsset(
232
- this.options.filename,
233
- new RawSource(this.options.serialize(manifest)),
234
+ this.options.filename || DEFAULT_FILENAME,
235
+ new RawSource(serialize(manifest)),
234
236
  { manifest: true }
235
237
  );
236
238
  }