webpack 5.95.0 → 5.96.1

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 (145) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EvalDevToolModulePlugin.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  20. package/lib/ExternalModule.js +40 -7
  21. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  22. package/lib/FileSystemInfo.js +12 -8
  23. package/lib/Generator.js +5 -4
  24. package/lib/HotModuleReplacementPlugin.js +8 -6
  25. package/lib/IgnorePlugin.js +19 -1
  26. package/lib/LoaderOptionsPlugin.js +3 -1
  27. package/lib/Module.js +9 -8
  28. package/lib/ModuleSourceTypesConstants.js +100 -0
  29. package/lib/NormalModule.js +27 -17
  30. package/lib/NormalModuleFactory.js +38 -22
  31. package/lib/OptionsApply.js +12 -1
  32. package/lib/ProgressPlugin.js +50 -10
  33. package/lib/RawModule.js +3 -4
  34. package/lib/RuntimeModule.js +3 -4
  35. package/lib/RuntimePlugin.js +11 -4
  36. package/lib/RuntimeTemplate.js +13 -42
  37. package/lib/SourceMapDevToolPlugin.js +10 -7
  38. package/lib/Watching.js +2 -2
  39. package/lib/WebpackOptionsApply.js +42 -21
  40. package/lib/asset/AssetGenerator.js +347 -194
  41. package/lib/asset/AssetModulesPlugin.js +2 -1
  42. package/lib/asset/AssetSourceGenerator.js +82 -27
  43. package/lib/asset/RawDataUrlModule.js +5 -4
  44. package/lib/buildChunkGraph.js +2 -2
  45. package/lib/cache/PackFileCacheStrategy.js +69 -31
  46. package/lib/cache/ResolverCachePlugin.js +248 -173
  47. package/lib/config/defaults.js +134 -126
  48. package/lib/container/ContainerEntryModule.js +3 -4
  49. package/lib/container/ContainerPlugin.js +8 -0
  50. package/lib/container/FallbackModule.js +2 -2
  51. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  52. package/lib/container/ModuleFederationPlugin.js +38 -1
  53. package/lib/container/RemoteModule.js +4 -2
  54. package/lib/container/RemoteRuntimeModule.js +4 -2
  55. package/lib/css/CssExportsGenerator.js +16 -12
  56. package/lib/css/CssGenerator.js +22 -16
  57. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  58. package/lib/css/CssModulesPlugin.js +122 -77
  59. package/lib/css/CssParser.js +655 -526
  60. package/lib/css/walkCssTokens.js +1168 -338
  61. package/lib/debug/ProfilingPlugin.js +5 -0
  62. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  63. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  64. package/lib/dependencies/CssExportDependency.js +3 -3
  65. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  66. package/lib/dependencies/CssUrlDependency.js +33 -3
  67. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  69. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  71. package/lib/dependencies/ImportParserPlugin.js +9 -7
  72. package/lib/dependencies/LoaderPlugin.js +19 -0
  73. package/lib/dependencies/SystemPlugin.js +2 -1
  74. package/lib/dependencies/URLPlugin.js +7 -1
  75. package/lib/dependencies/WorkerPlugin.js +1 -1
  76. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  77. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  78. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  79. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  80. package/lib/hmr/lazyCompilationBackend.js +1 -7
  81. package/lib/index.js +37 -7
  82. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  83. package/lib/javascript/JavascriptGenerator.js +8 -8
  84. package/lib/javascript/JavascriptModulesPlugin.js +126 -73
  85. package/lib/javascript/JavascriptParser.js +338 -117
  86. package/lib/json/JsonGenerator.js +5 -5
  87. package/lib/library/EnableLibraryPlugin.js +2 -2
  88. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  89. package/lib/library/UmdLibraryPlugin.js +16 -8
  90. package/lib/logging/Logger.js +11 -11
  91. package/lib/logging/createConsoleLogger.js +14 -14
  92. package/lib/logging/truncateArgs.js +1 -1
  93. package/lib/node/NodeWatchFileSystem.js +3 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  95. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  96. package/lib/node/nodeConsole.js +11 -8
  97. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  98. package/lib/optimize/ConcatenatedModule.js +43 -145
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  100. package/lib/optimize/InnerGraphPlugin.js +57 -16
  101. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  102. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  103. package/lib/optimize/RealContentHashPlugin.js +1 -1
  104. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  105. package/lib/rules/RuleSetCompiler.js +2 -2
  106. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  107. package/lib/schemes/DataUriPlugin.js +1 -1
  108. package/lib/serialization/BinaryMiddleware.js +32 -19
  109. package/lib/serialization/ObjectMiddleware.js +23 -9
  110. package/lib/serialization/SerializerMiddleware.js +3 -2
  111. package/lib/serialization/types.js +2 -2
  112. package/lib/sharing/ConsumeSharedModule.js +2 -3
  113. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  114. package/lib/sharing/ProvideSharedModule.js +2 -3
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  116. package/lib/stats/StatsFactory.js +12 -12
  117. package/lib/stats/StatsPrinter.js +7 -7
  118. package/lib/util/AsyncQueue.js +17 -1
  119. package/lib/util/IterableHelpers.js +1 -1
  120. package/lib/util/SetHelpers.js +1 -1
  121. package/lib/util/cleverMerge.js +48 -24
  122. package/lib/util/concatenate.js +227 -0
  123. package/lib/util/create-schema-validation.js +22 -9
  124. package/lib/util/deprecation.js +86 -28
  125. package/lib/util/fs.js +9 -9
  126. package/lib/util/hash/wasm-hash.js +12 -1
  127. package/lib/util/magicComment.js +21 -0
  128. package/lib/util/makeSerializable.js +24 -1
  129. package/lib/util/memoize.js +2 -1
  130. package/lib/util/runtime.js +4 -1
  131. package/lib/util/semver.js +130 -23
  132. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  133. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  134. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  135. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  136. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  137. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  138. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  139. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  140. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  141. package/package.json +18 -19
  142. package/schemas/WebpackOptions.check.js +1 -1
  143. package/schemas/WebpackOptions.json +8 -2
  144. package/types.d.ts +801 -259
  145. package/lib/util/mergeScope.js +0 -76
@@ -5,31 +5,18 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ DEFAULT_EXPORT,
10
+ NAMESPACE_OBJECT_EXPORT
11
+ } = require("./util/concatenate");
12
+
8
13
  /** @typedef {import("./Module")} Module */
14
+ /** @typedef {import("./optimize/ConcatenatedModule").ConcatenatedModuleInfo} ConcatenatedModuleInfo */
15
+ /** @typedef {import("./optimize/ConcatenatedModule").ModuleInfo} ModuleInfo */
9
16
 
10
17
  const MODULE_REFERENCE_REGEXP =
11
18
  /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
12
19
 
13
- const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
14
- const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
15
-
16
- /**
17
- * @typedef {object} ExternalModuleInfo
18
- * @property {number} index
19
- * @property {Module} module
20
- */
21
-
22
- /**
23
- * @typedef {object} ConcatenatedModuleInfo
24
- * @property {number} index
25
- * @property {Module} module
26
- * @property {Map<string, string>} exportMap mapping from export name to symbol
27
- * @property {Map<string, string>} rawExportMap mapping from export name to symbol
28
- * @property {string=} namespaceExportSymbol
29
- */
30
-
31
- /** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo} ModuleInfo */
32
-
33
20
  /**
34
21
  * @typedef {object} ModuleReferenceOptions
35
22
  * @property {string[]} ids the properties/exports of the module
@@ -9,6 +9,7 @@ const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
10
10
  const { makeWebpackError } = require("./HookWebpackError");
11
11
  const Module = require("./Module");
12
+ const { JS_TYPES } = require("./ModuleSourceTypesConstants");
12
13
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
13
14
  const RuntimeGlobals = require("./RuntimeGlobals");
14
15
  const Template = require("./Template");
@@ -37,13 +38,13 @@ const makeSerializable = require("./util/makeSerializable");
37
38
  /** @typedef {import("./Compilation")} Compilation */
38
39
  /** @typedef {import("./Dependency")} Dependency */
39
40
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
41
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
40
42
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
41
43
  /** @typedef {import("./Module").BuildMeta} BuildMeta */
42
44
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
43
45
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
44
46
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
45
47
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
46
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
47
48
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
48
49
  /** @typedef {import("./RequestShortener")} RequestShortener */
49
50
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
@@ -62,11 +63,11 @@ const makeSerializable = require("./util/makeSerializable");
62
63
  * @property {ContextMode} mode
63
64
  * @property {boolean} recursive
64
65
  * @property {RegExp} regExp
65
- * @property {"strict"|boolean=} namespaceObject
66
+ * @property {("strict" | boolean)=} namespaceObject
66
67
  * @property {string=} addon
67
- * @property {string=} chunkName
68
- * @property {RegExp=} include
69
- * @property {RegExp=} exclude
68
+ * @property {(string | null)=} chunkName
69
+ * @property {(RegExp | null)=} include
70
+ * @property {(RegExp | null)=} exclude
70
71
  * @property {RawChunkGroupOptions=} groupOptions
71
72
  * @property {string=} typePrefix
72
73
  * @property {string=} category
@@ -104,8 +105,6 @@ const makeSerializable = require("./util/makeSerializable");
104
105
 
105
106
  const SNAPSHOT_OPTIONS = { timestamp: true };
106
107
 
107
- const TYPES = new Set(["javascript"]);
108
-
109
108
  class ContextModule extends Module {
110
109
  /**
111
110
  * @param {ResolveDependencies} resolveDependencies function to get dependencies in this context
@@ -160,7 +159,7 @@ class ContextModule extends Module {
160
159
  * @returns {SourceTypes} types available (do not mutate)
161
160
  */
162
161
  getSourceTypes() {
163
- return TYPES;
162
+ return JS_TYPES;
164
163
  }
165
164
 
166
165
  /**
package/lib/CssModule.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Alexander Krasnoyarov @alexander-akait
3
+ Author Alexander Akait @alexander-akait
4
4
  */
5
5
 
6
6
  "use strict";
@@ -14,13 +14,13 @@ const makeSerializable = require("./util/makeSerializable");
14
14
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
15
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
16
 
17
- /** @typedef {string|undefined} CssLayer */
18
- /** @typedef {string|undefined} Supports */
19
- /** @typedef {string|undefined} Media */
20
- /** @typedef {[CssLayer?, Supports?, Media?]} InheritanceItem */
17
+ /** @typedef {string | undefined} CssLayer */
18
+ /** @typedef {string | undefined} Supports */
19
+ /** @typedef {string | undefined} Media */
20
+ /** @typedef {[CssLayer, Supports, Media]} InheritanceItem */
21
21
  /** @typedef {Array<InheritanceItem>} Inheritance */
22
22
 
23
- /** @typedef {NormalModuleCreateData & { cssLayer: CssLayer|null, supports: Supports|null, media: Media|null, inheritance: Inheritance|null }} CSSModuleCreateData */
23
+ /** @typedef {NormalModuleCreateData & { cssLayer: CssLayer, supports: Supports, media: Media, inheritance: Inheritance }} CSSModuleCreateData */
24
24
 
25
25
  class CssModule extends NormalModule {
26
26
  /**
@@ -127,30 +127,34 @@ class CssModule extends NormalModule {
127
127
  static deserialize(context) {
128
128
  const obj = new CssModule({
129
129
  // will be deserialized by Module
130
- layer: null,
130
+ layer: /** @type {EXPECTED_ANY} */ (null),
131
131
  type: "",
132
132
  // will be filled by updateCacheModule
133
133
  resource: "",
134
134
  context: "",
135
- request: null,
136
- userRequest: null,
137
- rawRequest: null,
138
- loaders: null,
139
- matchResource: null,
140
- parser: null,
141
- parserOptions: null,
142
- generator: null,
143
- generatorOptions: null,
144
- resolveOptions: null,
145
- cssLayer: null,
146
- supports: null,
147
- media: null,
148
- inheritance: null
135
+ request: /** @type {EXPECTED_ANY} */ (null),
136
+ userRequest: /** @type {EXPECTED_ANY} */ (null),
137
+ rawRequest: /** @type {EXPECTED_ANY} */ (null),
138
+ loaders: /** @type {EXPECTED_ANY} */ (null),
139
+ matchResource: /** @type {EXPECTED_ANY} */ (null),
140
+ parser: /** @type {EXPECTED_ANY} */ (null),
141
+ parserOptions: /** @type {EXPECTED_ANY} */ (null),
142
+ generator: /** @type {EXPECTED_ANY} */ (null),
143
+ generatorOptions: /** @type {EXPECTED_ANY} */ (null),
144
+ resolveOptions: /** @type {EXPECTED_ANY} */ (null),
145
+ cssLayer: /** @type {EXPECTED_ANY} */ (null),
146
+ supports: /** @type {EXPECTED_ANY} */ (null),
147
+ media: /** @type {EXPECTED_ANY} */ (null),
148
+ inheritance: /** @type {EXPECTED_ANY} */ (null)
149
149
  });
150
150
  obj.deserialize(context);
151
151
  return obj;
152
152
  }
153
153
 
154
+ /**
155
+ * @param {ObjectDeserializerContext} context context
156
+ * @returns {TODO} Module
157
+ */
154
158
  deserialize(context) {
155
159
  const { read } = context;
156
160
  this.cssLayer = read();
@@ -22,9 +22,9 @@ const {
22
22
  const createHash = require("./util/createHash");
23
23
 
24
24
  /** @typedef {import("estree").Expression} Expression */
25
- /** @typedef {import("./Compilation").ValueCacheVersion} ValueCacheVersion */
26
25
  /** @typedef {import("./Compiler")} Compiler */
27
26
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
27
+ /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
28
28
  /** @typedef {import("./NormalModule")} NormalModule */
29
29
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
30
30
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
@@ -45,6 +45,7 @@ const createHash = require("./util/createHash");
45
45
  * @property {string|function(): string=} version
46
46
  */
47
47
 
48
+ /** @typedef {string | Set<string>} ValueCacheVersion */
48
49
  /** @typedef {function({ module: NormalModule, key: string, readonly version: ValueCacheVersion }): CodeValuePrimitive} GeneratorFn */
49
50
 
50
51
  class RuntimeValue {
@@ -68,7 +69,7 @@ class RuntimeValue {
68
69
 
69
70
  /**
70
71
  * @param {JavascriptParser} parser the parser
71
- * @param {Map<string, ValueCacheVersion>} valueCacheVersions valueCacheVersions
72
+ * @param {ValueCacheVersions} valueCacheVersions valueCacheVersions
72
73
  * @param {string} key the defined key
73
74
  * @returns {CodeValuePrimitive} code
74
75
  */
@@ -107,7 +108,9 @@ class RuntimeValue {
107
108
  module: parser.state.module,
108
109
  key,
109
110
  get version() {
110
- return valueCacheVersions.get(VALUE_DEP_PREFIX + key);
111
+ return /** @type {ValueCacheVersion} */ (
112
+ valueCacheVersions.get(VALUE_DEP_PREFIX + key)
113
+ );
111
114
  }
112
115
  });
113
116
  }
@@ -136,7 +139,7 @@ function getObjKeys(properties) {
136
139
  /**
137
140
  * @param {any[]|{[k: string]: any}} obj obj
138
141
  * @param {JavascriptParser} parser Parser
139
- * @param {Map<string, ValueCacheVersion>} valueCacheVersions valueCacheVersions
142
+ * @param {ValueCacheVersions} valueCacheVersions valueCacheVersions
140
143
  * @param {string} key the defined key
141
144
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
142
145
  * @param {Logger} logger the logger object
@@ -209,7 +212,7 @@ const stringifyObj = (
209
212
  * Convert code to a string that evaluates
210
213
  * @param {CodeValue} code Code to evaluate
211
214
  * @param {JavascriptParser} parser Parser
212
- * @param {Map<string, ValueCacheVersion>} valueCacheVersions valueCacheVersions
215
+ * @param {ValueCacheVersions} valueCacheVersions valueCacheVersions
213
216
  * @param {string} key the defined key
214
217
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
215
218
  * @param {Logger} logger the logger object
@@ -377,7 +380,9 @@ class DefinePlugin {
377
380
  * @returns {void}
378
381
  */
379
382
  const handler = parser => {
380
- const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN);
383
+ const mainValue =
384
+ /** @type {ValueCacheVersion} */
385
+ (compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
381
386
  parser.hooks.program.tap(PLUGIN_NAME, () => {
382
387
  const buildInfo = /** @type {BuildInfo} */ (
383
388
  parser.state.module.buildInfo
@@ -397,7 +402,8 @@ class DefinePlugin {
397
402
  /** @type {NonNullable<BuildInfo["valueDependencies"]>} */
398
403
  (buildInfo.valueDependencies).set(
399
404
  VALUE_DEP_PREFIX + key,
400
- compilation.valueCacheVersions.get(VALUE_DEP_PREFIX + key)
405
+ /** @type {ValueCacheVersion} */
406
+ (compilation.valueCacheVersions.get(VALUE_DEP_PREFIX + key))
401
407
  );
402
408
  };
403
409
 
@@ -666,7 +672,7 @@ class DefinePlugin {
666
672
  const walkDefinitionsForValues = (definitions, prefix) => {
667
673
  for (const key of Object.keys(definitions)) {
668
674
  const code = definitions[key];
669
- const version = toCacheVersion(code);
675
+ const version = /** @type {string} */ (toCacheVersion(code));
670
676
  const name = VALUE_DEP_PREFIX + prefix + key;
671
677
  mainHash.update(`|${prefix}${key}`);
672
678
  const oldVersion = compilation.valueCacheVersions.get(name);
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JS_TYPES } = require("./ModuleSourceTypesConstants");
10
11
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
11
12
  const RuntimeGlobals = require("./RuntimeGlobals");
12
13
  const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
@@ -19,13 +20,13 @@ const makeSerializable = require("./util/makeSerializable");
19
20
  /** @typedef {import("./Compilation")} Compilation */
20
21
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
21
22
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
23
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
22
24
  /** @typedef {import("./LibManifestPlugin").ManifestModuleData} ManifestModuleData */
23
25
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
24
26
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
25
27
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
26
28
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
27
29
  /** @typedef {import("./Module").SourceContext} SourceContext */
28
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
29
30
  /** @typedef {import("./RequestShortener")} RequestShortener */
30
31
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
31
32
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -40,7 +41,6 @@ const makeSerializable = require("./util/makeSerializable");
40
41
  /** @typedef {"require" | "object"} Type */
41
42
  /** @typedef {TODO} Data */
42
43
 
43
- const TYPES = new Set(["javascript"]);
44
44
  const RUNTIME_REQUIREMENTS = new Set([
45
45
  RuntimeGlobals.module,
46
46
  RuntimeGlobals.require
@@ -74,7 +74,7 @@ class DelegatedModule extends Module {
74
74
  * @returns {SourceTypes} types available (do not mutate)
75
75
  */
76
76
  getSourceTypes() {
77
- return TYPES;
77
+ return JS_TYPES;
78
78
  }
79
79
 
80
80
  /**
package/lib/DllModule.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JS_TYPES } = require("./ModuleSourceTypesConstants");
10
11
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
11
12
  const RuntimeGlobals = require("./RuntimeGlobals");
12
13
  const makeSerializable = require("./util/makeSerializable");
@@ -18,11 +19,11 @@ const makeSerializable = require("./util/makeSerializable");
18
19
  /** @typedef {import("./Dependency")} Dependency */
19
20
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
20
21
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
22
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
21
23
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
22
24
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
23
25
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
24
26
  /** @typedef {import("./Module").SourceContext} SourceContext */
25
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
26
27
  /** @typedef {import("./RequestShortener")} RequestShortener */
27
28
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
28
29
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -32,7 +33,6 @@ const makeSerializable = require("./util/makeSerializable");
32
33
  /** @typedef {import("./util/Hash")} Hash */
33
34
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
34
35
 
35
- const TYPES = new Set(["javascript"]);
36
36
  const RUNTIME_REQUIREMENTS = new Set([
37
37
  RuntimeGlobals.require,
38
38
  RuntimeGlobals.module
@@ -57,7 +57,7 @@ class DllModule extends Module {
57
57
  * @returns {SourceTypes} types available (do not mutate)
58
58
  */
59
59
  getSourceTypes() {
60
- return TYPES;
60
+ return JS_TYPES;
61
61
  }
62
62
 
63
63
  /**
@@ -165,7 +165,7 @@ class DllModule extends Module {
165
165
  */
166
166
  cleanupForCache() {
167
167
  super.cleanupForCache();
168
- this.dependencies = undefined;
168
+ this.dependencies = /** @type {EXPECTED_ANY} */ (undefined);
169
169
  }
170
170
  }
171
171
 
@@ -9,6 +9,7 @@ const EntryOptionPlugin = require("./EntryOptionPlugin");
9
9
  const EntryPlugin = require("./EntryPlugin");
10
10
  const EntryDependency = require("./dependencies/EntryDependency");
11
11
 
12
+ /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
12
13
  /** @typedef {import("../declarations/WebpackOptions").EntryDynamicNormalized} EntryDynamic */
13
14
  /** @typedef {import("../declarations/WebpackOptions").EntryItem} EntryItem */
14
15
  /** @typedef {import("../declarations/WebpackOptions").EntryStaticNormalized} EntryStatic */
@@ -40,22 +41,27 @@ class DynamicEntryPlugin {
40
41
  }
41
42
  );
42
43
 
43
- compiler.hooks.make.tapPromise(
44
- "DynamicEntryPlugin",
45
- (compilation, callback) =>
46
- Promise.resolve(this.entry())
47
- .then(entry => {
48
- const promises = [];
49
- for (const name of Object.keys(entry)) {
50
- const desc = entry[name];
51
- const options = EntryOptionPlugin.entryDescriptionToOptions(
52
- compiler,
53
- name,
54
- desc
55
- );
56
- for (const entry of desc.import) {
57
- promises.push(
58
- new Promise((resolve, reject) => {
44
+ compiler.hooks.make.tapPromise("DynamicEntryPlugin", compilation =>
45
+ Promise.resolve(this.entry())
46
+ .then(entry => {
47
+ const promises = [];
48
+ for (const name of Object.keys(entry)) {
49
+ const desc = entry[name];
50
+ const options = EntryOptionPlugin.entryDescriptionToOptions(
51
+ compiler,
52
+ name,
53
+ desc
54
+ );
55
+ for (const entry of /** @type {NonNullable<EntryDescriptionNormalized["import"]>} */ (
56
+ desc.import
57
+ )) {
58
+ promises.push(
59
+ new Promise(
60
+ /**
61
+ * @param {(value?: any) => void} resolve resolve
62
+ * @param {(reason?: Error) => void} reject reject
63
+ */
64
+ (resolve, reject) => {
59
65
  compilation.addEntry(
60
66
  this.context,
61
67
  EntryPlugin.createDependency(entry, options),
@@ -65,13 +71,14 @@ class DynamicEntryPlugin {
65
71
  resolve();
66
72
  }
67
73
  );
68
- })
69
- );
70
- }
74
+ }
75
+ )
76
+ );
71
77
  }
72
- return Promise.all(promises);
73
- })
74
- .then(x => {})
78
+ }
79
+ return Promise.all(promises);
80
+ })
81
+ .then(x => {})
75
82
  );
76
83
  }
77
84
  }
@@ -57,7 +57,7 @@ class EvalDevToolModulePlugin {
57
57
  const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
58
58
  hooks.renderModuleContent.tap(
59
59
  "EvalDevToolModulePlugin",
60
- (source, module, { runtimeTemplate, chunkGraph }) => {
60
+ (source, module, { chunk, runtimeTemplate, chunkGraph }) => {
61
61
  const cacheEntry = cache.get(source);
62
62
  if (cacheEntry !== undefined) return cacheEntry;
63
63
  if (module instanceof ExternalModule) {
@@ -65,11 +65,14 @@ class EvalDevToolModulePlugin {
65
65
  return source;
66
66
  }
67
67
  const content = source.source();
68
+ const namespace = compilation.getPath(this.namespace, {
69
+ chunk
70
+ });
68
71
  const str = ModuleFilenameHelpers.createFilename(
69
72
  module,
70
73
  {
71
74
  moduleFilenameTemplate: this.moduleFilenameTemplate,
72
- namespace: this.namespace
75
+ namespace
73
76
  },
74
77
  {
75
78
  requestShortener: runtimeTemplate.requestShortener,
@@ -77,7 +77,7 @@ class EvalSourceMapDevToolPlugin {
77
77
  );
78
78
  hooks.renderModuleContent.tap(
79
79
  "EvalSourceMapDevToolPlugin",
80
- (source, m, { runtimeTemplate, chunkGraph }) => {
80
+ (source, m, { chunk, runtimeTemplate, chunkGraph }) => {
81
81
  const cachedSource = cache.get(source);
82
82
  if (cachedSource !== undefined) {
83
83
  return cachedSource;
@@ -113,6 +113,9 @@ class EvalSourceMapDevToolPlugin {
113
113
  return result(source);
114
114
  }
115
115
 
116
+ const namespace = compilation.getPath(this.namespace, {
117
+ chunk
118
+ });
116
119
  /** @type {SourceMap} */
117
120
  let sourceMap;
118
121
  let content;
@@ -143,7 +146,7 @@ class EvalSourceMapDevToolPlugin {
143
146
  module,
144
147
  {
145
148
  moduleFilenameTemplate: this.moduleFilenameTemplate,
146
- namespace: this.namespace
149
+ namespace
147
150
  },
148
151
  {
149
152
  requestShortener: runtimeTemplate.requestShortener,
@@ -11,6 +11,11 @@ const EnvironmentNotSupportAsyncWarning = require("./EnvironmentNotSupportAsyncW
11
11
  const { UsageState } = require("./ExportsInfo");
12
12
  const InitFragment = require("./InitFragment");
13
13
  const Module = require("./Module");
14
+ const {
15
+ JS_TYPES,
16
+ CSS_URL_TYPES,
17
+ CSS_IMPORT_TYPES
18
+ } = require("./ModuleSourceTypesConstants");
14
19
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
15
20
  const RuntimeGlobals = require("./RuntimeGlobals");
16
21
  const Template = require("./Template");
@@ -30,6 +35,7 @@ const { register } = require("./util/serialization");
30
35
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
31
36
  /** @typedef {import("./ExportsInfo")} ExportsInfo */
32
37
  /** @typedef {import("./Generator").GenerateContext} GenerateContext */
38
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
33
39
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
34
40
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
35
41
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
@@ -37,7 +43,6 @@ const { register } = require("./util/serialization");
37
43
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
38
44
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
39
45
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
40
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
41
46
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
42
47
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
43
48
  /** @typedef {import("./RequestShortener")} RequestShortener */
@@ -55,8 +60,9 @@ const { register } = require("./util/serialization");
55
60
 
56
61
  /** @typedef {{ attributes?: ImportAttributes, externalType: "import" | "module" | undefined }} ImportDependencyMeta */
57
62
  /** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
63
+ /** @typedef {{ sourceType: "css-url" }} AssetDependencyMeta */
58
64
 
59
- /** @typedef {ImportDependencyMeta | CssImportDependencyMeta} DependencyMeta */
65
+ /** @typedef {ImportDependencyMeta | CssImportDependencyMeta | AssetDependencyMeta} DependencyMeta */
60
66
 
61
67
  /**
62
68
  * @typedef {object} SourceData
@@ -67,8 +73,6 @@ const { register } = require("./util/serialization");
67
73
  * @property {ReadOnlyRuntimeRequirements=} runtimeRequirements
68
74
  */
69
75
 
70
- const TYPES = new Set(["javascript"]);
71
- const CSS_TYPES = new Set(["css-import"]);
72
76
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
73
77
  const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
74
78
  const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
@@ -500,7 +504,18 @@ class ExternalModule extends Module {
500
504
  * @returns {SourceTypes} types available (do not mutate)
501
505
  */
502
506
  getSourceTypes() {
503
- return this.externalType === "css-import" ? CSS_TYPES : TYPES;
507
+ if (
508
+ this.externalType === "asset" &&
509
+ this.dependencyMeta &&
510
+ /** @type {AssetDependencyMeta} */
511
+ (this.dependencyMeta).sourceType === "css-url"
512
+ ) {
513
+ return CSS_URL_TYPES;
514
+ } else if (this.externalType === "css-import") {
515
+ return CSS_IMPORT_TYPES;
516
+ }
517
+
518
+ return JS_TYPES;
504
519
  }
505
520
 
506
521
  /**
@@ -674,12 +689,24 @@ class ExternalModule extends Module {
674
689
  if (externalType === "module-import") {
675
690
  if (
676
691
  this.dependencyMeta &&
677
- /** @type {ImportDependencyMeta} */ (this.dependencyMeta).externalType
692
+ /** @type {ImportDependencyMeta} */
693
+ (this.dependencyMeta).externalType
678
694
  ) {
679
695
  return /** @type {ImportDependencyMeta} */ (this.dependencyMeta)
680
696
  .externalType;
681
697
  }
682
698
  return "module";
699
+ } else if (externalType === "asset") {
700
+ if (
701
+ this.dependencyMeta &&
702
+ /** @type {AssetDependencyMeta} */
703
+ (this.dependencyMeta).sourceType
704
+ ) {
705
+ return /** @type {AssetDependencyMeta} */ (this.dependencyMeta)
706
+ .sourceType;
707
+ }
708
+
709
+ return "asset";
683
710
  }
684
711
 
685
712
  return externalType;
@@ -816,7 +843,13 @@ class ExternalModule extends Module {
816
843
  new RawSource(`module.exports = ${JSON.stringify(request)};`)
817
844
  );
818
845
  const data = new Map();
819
- data.set("url", request);
846
+ data.set("url", { javascript: request });
847
+ return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
848
+ }
849
+ case "css-url": {
850
+ const sources = new Map();
851
+ const data = new Map();
852
+ data.set("url", { "css-url": request });
820
853
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
821
854
  }
822
855
  case "css-import": {