webpack 5.102.1 → 5.103.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +121 -134
  2. package/lib/CompatibilityPlugin.js +25 -2
  3. package/lib/Compilation.js +25 -2
  4. package/lib/ConcatenationScope.js +0 -15
  5. package/lib/CssModule.js +6 -1
  6. package/lib/DefinePlugin.js +11 -11
  7. package/lib/Dependency.js +8 -1
  8. package/lib/DependencyTemplate.js +1 -0
  9. package/lib/DotenvPlugin.js +457 -0
  10. package/lib/EnvironmentPlugin.js +19 -16
  11. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  12. package/lib/ExportsInfo.js +6 -2
  13. package/lib/ExternalModule.js +20 -28
  14. package/lib/ExternalModuleFactoryPlugin.js +10 -8
  15. package/lib/ExternalsPlugin.js +2 -1
  16. package/lib/ManifestPlugin.js +235 -0
  17. package/lib/Module.js +3 -0
  18. package/lib/ModuleGraph.js +2 -1
  19. package/lib/ModuleSourceTypesConstants.js +0 -6
  20. package/lib/MultiCompiler.js +1 -1
  21. package/lib/NodeStuffPlugin.js +419 -121
  22. package/lib/NormalModule.js +17 -16
  23. package/lib/RuntimeGlobals.js +22 -4
  24. package/lib/RuntimePlugin.js +27 -6
  25. package/lib/RuntimeTemplate.js +115 -56
  26. package/lib/SourceMapDevToolPlugin.js +20 -0
  27. package/lib/WebpackOptionsApply.js +33 -9
  28. package/lib/asset/AssetBytesGenerator.js +1 -1
  29. package/lib/asset/AssetGenerator.js +1 -2
  30. package/lib/asset/AssetSourceGenerator.js +1 -1
  31. package/lib/config/browserslistTargetHandler.js +5 -0
  32. package/lib/config/defaults.js +98 -18
  33. package/lib/config/normalization.js +2 -1
  34. package/lib/config/target.js +6 -0
  35. package/lib/css/CssGenerator.js +283 -57
  36. package/lib/css/CssLoadingRuntimeModule.js +2 -0
  37. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  38. package/lib/css/CssModulesPlugin.js +84 -34
  39. package/lib/css/CssParser.js +1174 -667
  40. package/lib/css/walkCssTokens.js +97 -0
  41. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  42. package/lib/dependencies/CommonJsPlugin.js +12 -0
  43. package/lib/dependencies/CssIcssExportDependency.js +247 -8
  44. package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
  45. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
  46. package/lib/dependencies/CssIcssImportDependency.js +60 -54
  47. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
  48. package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
  49. package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
  50. package/lib/dependencies/CssImportDependency.js +15 -5
  51. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  52. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
  53. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  54. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  55. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  56. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
  57. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
  58. package/lib/dependencies/HarmonyImportDependency.js +23 -27
  59. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  60. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  61. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  62. package/lib/dependencies/ImportDependency.js +8 -2
  63. package/lib/dependencies/ImportEagerDependency.js +6 -3
  64. package/lib/dependencies/ImportMetaPlugin.js +97 -9
  65. package/lib/dependencies/ImportParserPlugin.js +19 -21
  66. package/lib/dependencies/ImportPhase.js +121 -0
  67. package/lib/dependencies/ImportWeakDependency.js +6 -3
  68. package/lib/dependencies/ModuleDependency.js +5 -1
  69. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  70. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  71. package/lib/hmr/LazyCompilationPlugin.js +1 -0
  72. package/lib/ids/IdHelpers.js +4 -1
  73. package/lib/index.js +6 -0
  74. package/lib/javascript/ChunkHelpers.js +16 -5
  75. package/lib/javascript/JavascriptGenerator.js +101 -101
  76. package/lib/javascript/JavascriptModulesPlugin.js +23 -13
  77. package/lib/javascript/JavascriptParser.js +142 -38
  78. package/lib/json/JsonParser.js +7 -1
  79. package/lib/library/ModuleLibraryPlugin.js +0 -10
  80. package/lib/library/SystemLibraryPlugin.js +4 -0
  81. package/lib/library/UmdLibraryPlugin.js +1 -1
  82. package/lib/node/NodeTargetPlugin.js +9 -1
  83. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  84. package/lib/optimize/ConcatenatedModule.js +161 -135
  85. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  86. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  87. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  88. package/lib/util/comparators.js +4 -3
  89. package/lib/util/internalSerializables.js +4 -4
  90. package/lib/util/jsonParseEvenBetterErrors.js +10 -0
  91. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  92. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
  93. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
  94. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  95. package/lib/webpack.js +85 -82
  96. package/module.d.ts +5 -0
  97. package/package.json +16 -14
  98. package/schemas/WebpackOptions.check.js +1 -1
  99. package/schemas/WebpackOptions.json +109 -27
  100. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  101. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  102. package/schemas/plugins/ManifestPlugin.json +98 -0
  103. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  104. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  105. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  106. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  107. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  108. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  109. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  110. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  111. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  112. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  113. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  114. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  115. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  116. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  117. package/types.d.ts +560 -293
  118. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
@@ -28,6 +28,7 @@ const propertyAccess = require("./util/propertyAccess");
28
28
  const { register } = require("./util/serialization");
29
29
 
30
30
  /** @typedef {import("webpack-sources").Source} Source */
31
+ /** @typedef {import("../declarations/WebpackOptions").ExternalsType} ExternalsType */
31
32
  /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
32
33
  /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
33
34
  /** @typedef {import("./Chunk")} Chunk */
@@ -442,10 +443,6 @@ const getSourceForModuleExternal = (
442
443
  dependencyMeta,
443
444
  concatenationScope
444
445
  ) => {
445
- if (!Array.isArray(moduleAndSpecifiers)) {
446
- moduleAndSpecifiers = [moduleAndSpecifiers];
447
- }
448
-
449
446
  /** @type {Imported} */
450
447
  let imported = true;
451
448
  if (concatenationScope) {
@@ -465,6 +462,15 @@ const getSourceForModuleExternal = (
465
462
  }
466
463
  }
467
464
 
465
+ if (!Array.isArray(moduleAndSpecifiers)) {
466
+ moduleAndSpecifiers = [moduleAndSpecifiers];
467
+ }
468
+
469
+ // Return to `namespace` when the external request includes a specific export
470
+ if (moduleAndSpecifiers.length > 1) {
471
+ imported = true;
472
+ }
473
+
468
474
  const initFragment = new ModuleExternalInitFragment(
469
475
  moduleAndSpecifiers[0],
470
476
  imported,
@@ -473,22 +479,6 @@ const getSourceForModuleExternal = (
473
479
  runtimeTemplate.outputOptions.hashFunction
474
480
  );
475
481
  const normalizedImported = initFragment.getImported();
476
- const specifiers =
477
- normalizedImported === true
478
- ? undefined
479
- : /** @type {[string, string][]} */ (
480
- normalizedImported.map(([name, rawFinalName]) => {
481
- let finalName = rawFinalName;
482
- let counter = 0;
483
-
484
- if (concatenationScope) {
485
- while (!concatenationScope.registerUsedName(finalName)) {
486
- finalName = `${finalName}_${counter++}`;
487
- }
488
- }
489
- return [name, finalName];
490
- })
491
- );
492
482
 
493
483
  const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
494
484
  moduleAndSpecifiers,
@@ -518,7 +508,7 @@ const getSourceForModuleExternal = (
518
508
  "x"
519
509
  )}`
520
510
  : undefined,
521
- specifiers,
511
+ specifiers: normalizedImported === true ? undefined : normalizedImported,
522
512
  runtimeRequirements: moduleRemapping
523
513
  ? RUNTIME_REQUIREMENTS_FOR_MODULE
524
514
  : undefined,
@@ -632,7 +622,7 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
632
622
  class ExternalModule extends Module {
633
623
  /**
634
624
  * @param {ExternalModuleRequest} request request
635
- * @param {string} type type
625
+ * @param {ExternalsType} type type
636
626
  * @param {string} userRequest user request
637
627
  * @param {DependencyMeta=} dependencyMeta dependency meta
638
628
  */
@@ -642,7 +632,7 @@ class ExternalModule extends Module {
642
632
  // Info from Factory
643
633
  /** @type {ExternalModuleRequest} */
644
634
  this.request = request;
645
- /** @type {string} */
635
+ /** @type {ExternalsType} */
646
636
  this.externalType = type;
647
637
  /** @type {string} */
648
638
  this.userRequest = userRequest;
@@ -821,6 +811,10 @@ class ExternalModule extends Module {
821
811
  return undefined;
822
812
  }
823
813
 
814
+ /**
815
+ * @private
816
+ * @returns {{ request: string | string[], externalType: ExternalsType }} the request and external type
817
+ */
824
818
  _getRequestAndExternalType() {
825
819
  let { request, externalType } = this;
826
820
  if (typeof request === "object" && !Array.isArray(request)) {
@@ -833,8 +827,8 @@ class ExternalModule extends Module {
833
827
  /**
834
828
  * Resolve the detailed external type from the raw external type.
835
829
  * e.g. resolve "module" or "import" from "module-import" type
836
- * @param {string} externalType raw external type
837
- * @returns {string} resolved external type
830
+ * @param {ExternalsType} externalType raw external type
831
+ * @returns {ExternalsType} resolved external type
838
832
  */
839
833
  _resolveExternalType(externalType) {
840
834
  if (externalType === "module-import") {
@@ -866,7 +860,7 @@ class ExternalModule extends Module {
866
860
  /**
867
861
  * @private
868
862
  * @param {string | string[]} request request
869
- * @param {string} externalType the external type
863
+ * @param {ExternalsType} externalType the external type
870
864
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
871
865
  * @param {ModuleGraph} moduleGraph the module graph
872
866
  * @param {ChunkGraph} chunkGraph the chunk graph
@@ -959,8 +953,6 @@ class ExternalModule extends Module {
959
953
  }
960
954
  case "var":
961
955
  case "promise":
962
- case "const":
963
- case "let":
964
956
  case "assign":
965
957
  default:
966
958
  return getSourceForDefaultCase(
@@ -16,6 +16,7 @@ const { cachedSetProperty, resolveByProperty } = require("./util/cleverMerge");
16
16
 
17
17
  /** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
18
18
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
19
+ /** @typedef {import("../declarations/WebpackOptions").ExternalsType} ExternalsType */
19
20
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
20
21
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
21
22
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
@@ -50,7 +51,7 @@ const callDeprecatedExternals = util.deprecate(
50
51
  * @param {EXPECTED_FUNCTION} externalsFunction externals function
51
52
  * @param {string} context context
52
53
  * @param {string} request request
53
- * @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty: ExternalType | undefined) => void} cb cb
54
+ * @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty: ExternalsType | undefined) => void} cb cb
54
55
  */
55
56
  (externalsFunction, context, request, cb) => {
56
57
  // eslint-disable-next-line no-useless-call
@@ -90,13 +91,12 @@ const resolveLayer = (obj, layer) => {
90
91
  };
91
92
 
92
93
  /** @typedef {string | string[] | boolean | Record<string, string | string[]>} ExternalValue */
93
- /** @typedef {string | undefined} ExternalType */
94
94
 
95
95
  const PLUGIN_NAME = "ExternalModuleFactoryPlugin";
96
96
 
97
97
  class ExternalModuleFactoryPlugin {
98
98
  /**
99
- * @param {string} type default external type
99
+ * @param {ExternalsType} type default external type
100
100
  * @param {Externals} externals externals config
101
101
  */
102
102
  constructor(type, externals) {
@@ -122,7 +122,7 @@ class ExternalModuleFactoryPlugin {
122
122
 
123
123
  /**
124
124
  * @param {ExternalValue} value the external config
125
- * @param {ExternalType | undefined} type type of external
125
+ * @param {ExternalsType | undefined} type type of external
126
126
  * @param {HandleExternalCallback} callback callback
127
127
  * @returns {void}
128
128
  */
@@ -131,7 +131,7 @@ class ExternalModuleFactoryPlugin {
131
131
  // Not externals, fallback to original factory
132
132
  return callback();
133
133
  }
134
- /** @type {string | string[] | Record<string, string|string[]>} */
134
+ /** @type {ExternalValue} */
135
135
  let externalConfig = value === true ? dependency.request : value;
136
136
  // When no explicit type is specified, extract it from the externalConfig
137
137
  if (type === undefined) {
@@ -140,7 +140,9 @@ class ExternalModuleFactoryPlugin {
140
140
  UNSPECIFIED_EXTERNAL_TYPE_REGEXP.test(externalConfig)
141
141
  ) {
142
142
  const idx = externalConfig.indexOf(" ");
143
- type = externalConfig.slice(0, idx);
143
+ type =
144
+ /** @type {ExternalsType} */
145
+ (externalConfig.slice(0, idx));
144
146
  externalConfig = externalConfig.slice(idx + 1);
145
147
  } else if (
146
148
  Array.isArray(externalConfig) &&
@@ -149,7 +151,7 @@ class ExternalModuleFactoryPlugin {
149
151
  ) {
150
152
  const firstItem = externalConfig[0];
151
153
  const idx = firstItem.indexOf(" ");
152
- type = firstItem.slice(0, idx);
154
+ type = /** @type {ExternalsType} */ (firstItem.slice(0, idx));
153
155
  externalConfig = [
154
156
  firstItem.slice(idx + 1),
155
157
  ...externalConfig.slice(1)
@@ -255,7 +257,7 @@ class ExternalModuleFactoryPlugin {
255
257
  /**
256
258
  * @param {Error | null | undefined} err err
257
259
  * @param {ExternalValue=} value value
258
- * @param {ExternalType=} type type
260
+ * @param {ExternalsType=} type type
259
261
  * @returns {void}
260
262
  */
261
263
  const cb = (err, value, type) => {
@@ -9,6 +9,7 @@ const { ModuleExternalInitFragment } = require("./ExternalModule");
9
9
  const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
10
10
  const ConcatenatedModule = require("./optimize/ConcatenatedModule");
11
11
 
12
+ /** @typedef {import("../declarations/WebpackOptions").ExternalsType} ExternalsType */
12
13
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
13
14
  /** @typedef {import("./Compiler")} Compiler */
14
15
  /** @typedef {import("./ExternalModule").Imported} Imported */
@@ -17,7 +18,7 @@ const PLUGIN_NAME = "ExternalsPlugin";
17
18
 
18
19
  class ExternalsPlugin {
19
20
  /**
20
- * @param {string} type default external type
21
+ * @param {ExternalsType} type default external type
21
22
  * @param {Externals} externals externals config
22
23
  */
23
24
  constructor(type, externals) {
@@ -0,0 +1,235 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Haijie Xie @hai-x
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { RawSource } = require("webpack-sources");
9
+ const Compilation = require("./Compilation");
10
+ const HotUpdateChunk = require("./HotUpdateChunk");
11
+ const createSchemaValidation = require("./util/create-schema-validation");
12
+
13
+ /** @typedef {import("./Compiler")} Compiler */
14
+ /** @typedef {import("./Chunk")} Chunk */
15
+ /** @typedef {import("./Chunk").ChunkName} ChunkName */
16
+ /** @typedef {import("./Chunk").ChunkId} ChunkId */
17
+ /** @typedef {import("./Compilation").Asset} Asset */
18
+ /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
19
+
20
+ /** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestPluginOptions} ManifestPluginOptions */
21
+ /** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestObject} ManifestObject */
22
+ /** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestEntrypoint} ManifestEntrypoint */
23
+ /** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestItem} ManifestItem */
24
+
25
+ const PLUGIN_NAME = "ManifestPlugin";
26
+
27
+ const validate = createSchemaValidation(
28
+ require("../schemas/plugins/ManifestPlugin.check"),
29
+ () => require("../schemas/plugins/ManifestPlugin.json"),
30
+ {
31
+ name: "ManifestPlugin",
32
+ baseDataPath: "options"
33
+ }
34
+ );
35
+
36
+ /**
37
+ * @param {string} filename filename
38
+ * @returns {string} extname
39
+ */
40
+ const extname = (filename) => {
41
+ const replaced = filename.replace(/\?.*/, "");
42
+ const split = replaced.split(".");
43
+ const last = split.pop();
44
+ if (!last) return "";
45
+ return last && /^(gz|br|map)$/i.test(last) ? `${split.pop()}.${last}` : last;
46
+ };
47
+
48
+ class ManifestPlugin {
49
+ /**
50
+ * @param {ManifestPluginOptions} options options
51
+ */
52
+ constructor(options) {
53
+ validate(options);
54
+
55
+ /** @type {ManifestPluginOptions & Required<Omit<ManifestPluginOptions, "filter" | "generate">>} */
56
+ this.options = {
57
+ filename: "manifest.json",
58
+ prefix: "[publicpath]",
59
+ entrypoints: true,
60
+ serialize: (manifest) => JSON.stringify(manifest, null, 2),
61
+ ...options
62
+ };
63
+ }
64
+
65
+ /**
66
+ * Apply the plugin
67
+ * @param {Compiler} compiler the compiler instance
68
+ * @returns {void}
69
+ */
70
+ apply(compiler) {
71
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
72
+ compilation.hooks.processAssets.tap(
73
+ {
74
+ name: PLUGIN_NAME,
75
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
76
+ },
77
+ () => {
78
+ const hashDigestLength = compilation.outputOptions.hashDigestLength;
79
+ const publicPath = compilation.getPath(
80
+ compilation.outputOptions.publicPath
81
+ );
82
+
83
+ /**
84
+ * @param {string | string[]} value value
85
+ * @returns {RegExp} regexp to remove hash
86
+ */
87
+ const createHashRegExp = (value) =>
88
+ new RegExp(
89
+ `(?:\\.${Array.isArray(value) ? `(${value.join("|")})` : value})(?=\\.)`,
90
+ "gi"
91
+ );
92
+
93
+ /**
94
+ * @param {string} name name
95
+ * @param {AssetInfo | null} info asset info
96
+ * @returns {string} hash removed name
97
+ */
98
+ const removeHash = (name, info) => {
99
+ // Handles hashes that match configured `hashDigestLength`
100
+ // i.e. index.XXXX.html -> index.html (html-webpack-plugin)
101
+ if (hashDigestLength <= 0) return name;
102
+ const reg = createHashRegExp(`[a-f0-9]{${hashDigestLength},32}`);
103
+ return name.replace(reg, "");
104
+ };
105
+
106
+ /**
107
+ * @param {Chunk} chunk chunk
108
+ * @returns {ChunkName | ChunkId} chunk name or chunk id
109
+ */
110
+ const getName = (chunk) => {
111
+ if (chunk.name) return chunk.name;
112
+
113
+ return chunk.id;
114
+ };
115
+
116
+ /** @type {ManifestObject} */
117
+ let manifest = {};
118
+
119
+ if (this.options.entrypoints) {
120
+ /** @type {ManifestObject["entrypoints"]} */
121
+ const entrypoints = {};
122
+
123
+ for (const [name, entrypoint] of compilation.entrypoints) {
124
+ const imports = [];
125
+
126
+ for (const chunk of entrypoint.chunks) {
127
+ for (const file of chunk.files) {
128
+ const name = getName(chunk);
129
+
130
+ imports.push(name ? `${name}.${extname(file)}` : file);
131
+ }
132
+ }
133
+
134
+ /** @type {ManifestEntrypoint} */
135
+ const item = { imports };
136
+ const parents = entrypoint
137
+ .getParents()
138
+ .map((item) => /** @type {string} */ (item.name));
139
+
140
+ if (parents.length > 0) {
141
+ item.parents = parents;
142
+ }
143
+
144
+ entrypoints[name] = item;
145
+ }
146
+
147
+ manifest.entrypoints = entrypoints;
148
+ }
149
+
150
+ /** @type {ManifestObject["assets"]} */
151
+ const assets = {};
152
+
153
+ /** @type {Set<string>} */
154
+ const added = new Set();
155
+
156
+ /**
157
+ * @param {string} file file
158
+ * @param {string=} usedName usedName
159
+ * @returns {void}
160
+ */
161
+ const handleFile = (file, usedName) => {
162
+ if (added.has(file)) return;
163
+ added.add(file);
164
+
165
+ const asset = compilation.getAsset(file);
166
+ if (!asset) return;
167
+ const sourceFilename = asset.info.sourceFilename;
168
+ const name =
169
+ usedName ||
170
+ sourceFilename ||
171
+ // Fallback for unofficial plugins, just remove hash from filename
172
+ removeHash(file, asset.info);
173
+
174
+ const prefix = this.options.prefix.replace(
175
+ /\[publicpath\]/gi,
176
+ () => (publicPath === "auto" ? "/" : publicPath)
177
+ );
178
+ /** @type {ManifestItem} */
179
+ const item = { file: prefix + file };
180
+
181
+ if (sourceFilename) {
182
+ item.src = sourceFilename;
183
+ }
184
+
185
+ if (this.options.filter) {
186
+ const needKeep = this.options.filter(item);
187
+
188
+ if (!needKeep) {
189
+ return;
190
+ }
191
+ }
192
+
193
+ assets[name] = item;
194
+ };
195
+
196
+ for (const chunk of compilation.chunks) {
197
+ if (chunk instanceof HotUpdateChunk) continue;
198
+
199
+ for (const auxiliaryFile of chunk.auxiliaryFiles) {
200
+ handleFile(auxiliaryFile);
201
+ }
202
+
203
+ const name = getName(chunk);
204
+
205
+ for (const file of chunk.files) {
206
+ handleFile(file, name ? `${name}.${extname(file)}` : file);
207
+ }
208
+ }
209
+
210
+ for (const asset of compilation.getAssets()) {
211
+ if (asset.info.hotModuleReplacement) {
212
+ continue;
213
+ }
214
+
215
+ handleFile(asset.name);
216
+ }
217
+
218
+ manifest.assets = assets;
219
+
220
+ if (this.options.generate) {
221
+ manifest = this.options.generate(manifest);
222
+ }
223
+
224
+ compilation.emitAsset(
225
+ this.options.filename,
226
+ new RawSource(this.options.serialize(manifest)),
227
+ { manifest: true }
228
+ );
229
+ }
230
+ );
231
+ });
232
+ }
233
+ }
234
+
235
+ module.exports = ManifestPlugin;
package/lib/Module.js CHANGED
@@ -39,6 +39,8 @@ const makeSerializable = require("./util/makeSerializable");
39
39
  /** @typedef {import("./RequestShortener")} RequestShortener */
40
40
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
41
41
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
42
+ /** @typedef {import("../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
43
+
42
44
  /**
43
45
  * @template T
44
46
  * @typedef {import("./InitFragment")<T>} InitFragment
@@ -116,6 +118,7 @@ const makeSerializable = require("./util/makeSerializable");
116
118
  /**
117
119
  * @typedef {object} KnownBuildMeta
118
120
  * @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
121
+ * @property {CssParserExportType=} exportType
119
122
  * @property {(false | "redirect" | "redirect-warn")=} defaultObject
120
123
  * @property {boolean=} strictHarmonyModule
121
124
  * @property {boolean=} treatAsCommonJs
@@ -9,6 +9,7 @@ const util = require("util");
9
9
  const ExportsInfo = require("./ExportsInfo");
10
10
  const ModuleGraphConnection = require("./ModuleGraphConnection");
11
11
  const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
12
+ const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
12
13
  const SortableSet = require("./util/SortableSet");
13
14
  const WeakTupleMap = require("./util/WeakTupleMap");
14
15
  const { sortWithSourceOrder } = require("./util/comparators");
@@ -844,7 +845,7 @@ class ModuleGraph {
844
845
  ) {
845
846
  continue;
846
847
  }
847
- if (connection.dependency.defer) return true;
848
+ if (ImportPhaseUtils.isDefer(connection.dependency.phase)) return true;
848
849
  }
849
850
  return false;
850
851
  }
@@ -44,11 +44,6 @@ const JS_TYPE = "javascript";
44
44
  */
45
45
  const JS_TYPES = new Set(["javascript"]);
46
46
 
47
- /**
48
- * @type {ReadonlySet<"javascript" | "css-export">}
49
- */
50
- const JS_AND_CSS_EXPORT_TYPES = new Set(["javascript", "css-export"]);
51
-
52
47
  /**
53
48
  * @type {ReadonlySet<"javascript" | "css-url">}
54
49
  */
@@ -111,7 +106,6 @@ module.exports.CSS_IMPORT_TYPES = CSS_IMPORT_TYPES;
111
106
  module.exports.CSS_TYPE = CSS_TYPE;
112
107
  module.exports.CSS_TYPES = CSS_TYPES;
113
108
  module.exports.CSS_URL_TYPES = CSS_URL_TYPES;
114
- module.exports.JS_AND_CSS_EXPORT_TYPES = JS_AND_CSS_EXPORT_TYPES;
115
109
  module.exports.JS_AND_CSS_TYPES = JS_AND_CSS_TYPES;
116
110
  module.exports.JS_AND_CSS_URL_TYPES = JS_AND_CSS_URL_TYPES;
117
111
  module.exports.JS_TYPE = JS_TYPE;
@@ -23,7 +23,7 @@ const ArrayQueue = require("./util/ArrayQueue");
23
23
  * @template R
24
24
  * @typedef {import("tapable").SyncBailHook<T, R>} SyncBailHook<T, R>
25
25
  */
26
- /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
26
+ /** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
27
27
  /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
28
28
  /** @typedef {import("./Compiler")} Compiler */
29
29
  /**