webpack 5.102.1 → 5.104.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 (220) hide show
  1. package/README.md +121 -134
  2. package/hot/dev-server.js +18 -3
  3. package/hot/emitter-event-target.js +7 -0
  4. package/hot/lazy-compilation-node.js +45 -29
  5. package/hot/lazy-compilation-universal.js +18 -0
  6. package/hot/lazy-compilation-web.js +15 -5
  7. package/hot/load-http.js +7 -0
  8. package/hot/only-dev-server.js +19 -4
  9. package/lib/APIPlugin.js +6 -0
  10. package/lib/Chunk.js +1 -1
  11. package/lib/ChunkGraph.js +9 -7
  12. package/lib/ChunkGroup.js +8 -5
  13. package/lib/CleanPlugin.js +6 -3
  14. package/lib/CodeGenerationResults.js +2 -1
  15. package/lib/CompatibilityPlugin.js +28 -2
  16. package/lib/Compilation.js +58 -21
  17. package/lib/Compiler.js +3 -3
  18. package/lib/ConcatenationScope.js +0 -15
  19. package/lib/ContextModule.js +6 -3
  20. package/lib/ContextModuleFactory.js +6 -4
  21. package/lib/CssModule.js +6 -1
  22. package/lib/DefinePlugin.js +45 -14
  23. package/lib/DelegatedModule.js +7 -4
  24. package/lib/Dependency.js +8 -1
  25. package/lib/DependencyTemplate.js +1 -0
  26. package/lib/DllModule.js +6 -3
  27. package/lib/DotenvPlugin.js +462 -0
  28. package/lib/EnvironmentPlugin.js +19 -16
  29. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  30. package/lib/ExportsInfo.js +6 -2
  31. package/lib/ExternalModule.js +28 -35
  32. package/lib/ExternalModuleFactoryPlugin.js +11 -9
  33. package/lib/ExternalsPlugin.js +2 -1
  34. package/lib/FileSystemInfo.js +1 -1
  35. package/lib/Generator.js +10 -7
  36. package/lib/HookWebpackError.js +33 -4
  37. package/lib/HotModuleReplacementPlugin.js +22 -0
  38. package/lib/ManifestPlugin.js +235 -0
  39. package/lib/Module.js +27 -15
  40. package/lib/ModuleBuildError.js +1 -1
  41. package/lib/ModuleError.js +1 -1
  42. package/lib/ModuleFilenameHelpers.js +1 -1
  43. package/lib/ModuleGraph.js +29 -13
  44. package/lib/ModuleGraphConnection.js +2 -2
  45. package/lib/ModuleSourceTypeConstants.js +189 -0
  46. package/lib/ModuleTypeConstants.js +1 -4
  47. package/lib/ModuleWarning.js +1 -1
  48. package/lib/MultiCompiler.js +1 -1
  49. package/lib/NodeStuffPlugin.js +424 -116
  50. package/lib/NormalModule.js +23 -20
  51. package/lib/NormalModuleFactory.js +7 -10
  52. package/lib/Parser.js +1 -1
  53. package/lib/RawModule.js +7 -4
  54. package/lib/RuntimeGlobals.js +22 -4
  55. package/lib/RuntimeModule.js +1 -1
  56. package/lib/RuntimePlugin.js +27 -6
  57. package/lib/RuntimeTemplate.js +120 -57
  58. package/lib/SourceMapDevToolPlugin.js +26 -1
  59. package/lib/Template.js +17 -6
  60. package/lib/TemplatedPathPlugin.js +5 -6
  61. package/lib/WebpackError.js +0 -1
  62. package/lib/WebpackOptionsApply.js +67 -15
  63. package/lib/asset/AssetBytesGenerator.js +16 -12
  64. package/lib/asset/AssetGenerator.js +31 -26
  65. package/lib/asset/AssetSourceGenerator.js +16 -12
  66. package/lib/asset/RawDataUrlModule.js +6 -3
  67. package/lib/buildChunkGraph.js +4 -2
  68. package/lib/cache/PackFileCacheStrategy.js +6 -5
  69. package/lib/cli.js +2 -43
  70. package/lib/config/browserslistTargetHandler.js +24 -0
  71. package/lib/config/defaults.js +226 -61
  72. package/lib/config/normalization.js +4 -3
  73. package/lib/config/target.js +11 -0
  74. package/lib/container/ContainerEntryModule.js +6 -3
  75. package/lib/container/FallbackModule.js +6 -3
  76. package/lib/container/RemoteModule.js +1 -3
  77. package/lib/css/CssGenerator.js +304 -76
  78. package/lib/css/CssLoadingRuntimeModule.js +14 -4
  79. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  80. package/lib/css/CssModulesPlugin.js +72 -67
  81. package/lib/css/CssParser.js +1726 -732
  82. package/lib/css/walkCssTokens.js +128 -11
  83. package/lib/dependencies/CachedConstDependency.js +24 -10
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  85. package/lib/dependencies/CommonJsPlugin.js +12 -0
  86. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  88. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +389 -12
  90. package/lib/dependencies/CssIcssImportDependency.js +114 -51
  91. package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
  92. package/lib/dependencies/CssImportDependency.js +17 -6
  93. package/lib/dependencies/CssUrlDependency.js +3 -2
  94. package/lib/dependencies/DynamicExports.js +7 -7
  95. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  96. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  97. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  98. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  99. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  100. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  101. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
  102. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
  103. package/lib/dependencies/HarmonyExports.js +4 -4
  104. package/lib/dependencies/HarmonyImportDependency.js +28 -27
  105. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  106. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  107. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  108. package/lib/dependencies/ImportDependency.js +8 -2
  109. package/lib/dependencies/ImportEagerDependency.js +6 -3
  110. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  111. package/lib/dependencies/ImportMetaPlugin.js +154 -9
  112. package/lib/dependencies/ImportParserPlugin.js +21 -23
  113. package/lib/dependencies/ImportPhase.js +121 -0
  114. package/lib/dependencies/ImportWeakDependency.js +6 -3
  115. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  116. package/lib/dependencies/ModuleDependency.js +5 -1
  117. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  118. package/lib/dependencies/WorkerPlugin.js +2 -2
  119. package/lib/dependencies/getFunctionExpression.js +1 -1
  120. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  121. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  122. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  123. package/lib/hmr/LazyCompilationPlugin.js +5 -3
  124. package/lib/ids/IdHelpers.js +20 -8
  125. package/lib/index.js +6 -0
  126. package/lib/javascript/ChunkHelpers.js +16 -5
  127. package/lib/javascript/JavascriptGenerator.js +105 -104
  128. package/lib/javascript/JavascriptModulesPlugin.js +80 -37
  129. package/lib/javascript/JavascriptParser.js +161 -44
  130. package/lib/json/JsonGenerator.js +5 -4
  131. package/lib/json/JsonParser.js +9 -2
  132. package/lib/library/AbstractLibraryPlugin.js +1 -1
  133. package/lib/library/AmdLibraryPlugin.js +4 -1
  134. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  135. package/lib/library/ModuleLibraryPlugin.js +41 -23
  136. package/lib/library/SystemLibraryPlugin.js +8 -1
  137. package/lib/library/UmdLibraryPlugin.js +2 -2
  138. package/lib/logging/Logger.js +5 -4
  139. package/lib/logging/createConsoleLogger.js +2 -2
  140. package/lib/node/NodeTargetPlugin.js +9 -1
  141. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  142. package/lib/optimize/ConcatenatedModule.js +208 -167
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  144. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  145. package/lib/optimize/SplitChunksPlugin.js +60 -46
  146. package/lib/rules/RuleSetCompiler.js +1 -1
  147. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  148. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  149. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  150. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  151. package/lib/schemes/HttpUriPlugin.js +78 -7
  152. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  153. package/lib/serialization/ObjectMiddleware.js +0 -2
  154. package/lib/serialization/SingleItemMiddleware.js +1 -1
  155. package/lib/sharing/ConsumeSharedModule.js +1 -1
  156. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  157. package/lib/sharing/ProvideSharedModule.js +1 -1
  158. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  159. package/lib/sharing/utils.js +1 -1
  160. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  161. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  162. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  163. package/lib/util/StringXor.js +1 -1
  164. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  165. package/lib/util/binarySearchBounds.js +2 -2
  166. package/lib/util/comparators.js +54 -76
  167. package/lib/util/compileBooleanMatcher.js +78 -6
  168. package/lib/util/createHash.js +20 -199
  169. package/lib/util/deprecation.js +1 -1
  170. package/lib/util/deterministicGrouping.js +6 -3
  171. package/lib/util/fs.js +75 -75
  172. package/lib/util/hash/BatchedHash.js +10 -9
  173. package/lib/util/hash/BulkUpdateHash.js +138 -0
  174. package/lib/util/hash/DebugHash.js +75 -0
  175. package/lib/util/hash/hash-digest.js +216 -0
  176. package/lib/util/identifier.js +82 -17
  177. package/lib/util/internalSerializables.js +2 -6
  178. package/lib/util/runtime.js +3 -3
  179. package/lib/util/source.js +2 -2
  180. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  181. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  182. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
  183. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  184. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
  185. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  186. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  187. package/lib/webpack.js +85 -82
  188. package/module.d.ts +5 -0
  189. package/package.json +34 -28
  190. package/schemas/WebpackOptions.check.js +1 -1
  191. package/schemas/WebpackOptions.json +160 -101
  192. package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
  193. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  194. package/schemas/plugins/ManifestPlugin.json +98 -0
  195. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  196. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  197. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  198. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  199. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  200. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  201. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  202. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  203. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  204. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  205. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  206. package/types.d.ts +771 -436
  207. package/lib/ModuleSourceTypesConstants.js +0 -123
  208. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  209. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
  210. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  211. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  212. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  213. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  214. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  215. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  216. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  217. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  218. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  219. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  220. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -5,40 +5,117 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const WebpackError = require("../WebpackError");
9
+ const { cssExportConvention } = require("../util/conventions");
8
10
  const makeSerializable = require("../util/makeSerializable");
9
- const CssIcssExportDependency = require("./CssIcssExportDependency");
10
- const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
11
- const ModuleDependency = require("./ModuleDependency");
11
+ const memoize = require("../util/memoize");
12
+ const CssImportDependency = require("./CssImportDependency");
12
13
 
13
14
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
15
  /** @typedef {import("../Dependency")} Dependency */
15
16
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
16
17
  /** @typedef {import("../Module")} Module */
18
+ /** @typedef {import("../CssModule")} CssModule */
19
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
20
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
17
21
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
18
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
23
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
24
+ /** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
25
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
26
+ /** @typedef {import("./CssIcssExportDependency").ExportMode} ExportMode */
27
+ /** @typedef {import("./CssIcssExportDependency").ExportType} ExportType */
20
28
 
21
- class CssIcssImportDependency extends ModuleDependency {
29
+ const getCssIcssExportDependency = memoize(() =>
30
+ require("./CssIcssExportDependency")
31
+ );
32
+
33
+ class CssIcssImportDependency extends CssImportDependency {
22
34
  /**
23
35
  * Example of dependency:
24
36
  *
25
- *:import('./style.css') { IMPORTED_NAME: v-primary }
37
+ * :import('./style.css') { value: name }
26
38
  * @param {string} request request request path which needs resolving
27
- * @param {string} exportName export name
28
39
  * @param {Range} range the range of dependency
40
+ * @param {"local" | "global"} mode mode of the parsed CSS
41
+ * @param {string} name name
42
+ * @param {string=} exportName export value
43
+ * @param {ExportMode=} exportMode export mode
44
+ * @param {ExportType=} exportType export type
29
45
  */
30
- constructor(request, exportName, range) {
31
- super(request);
32
- this.exportName = exportName;
33
- this.range = range;
46
+ constructor(
47
+ request,
48
+ range,
49
+ mode,
50
+ name,
51
+ exportName = undefined,
52
+ exportMode = getCssIcssExportDependency().EXPORT_MODE.NONE,
53
+ exportType = getCssIcssExportDependency().EXPORT_TYPE.NORMAL
54
+ ) {
55
+ super(request, range, mode);
56
+ this.name = name;
57
+ this.value = exportName;
58
+ this.interpolate = true;
59
+ this.exportMode = exportMode;
60
+ this.exportType = exportType;
34
61
  }
35
62
 
36
63
  get type() {
37
64
  return "css :import";
38
65
  }
39
66
 
40
- get category() {
41
- return "css-import";
67
+ /**
68
+ * @returns {string | null} an identifier to merge equal requests
69
+ */
70
+ getResourceIdentifier() {
71
+ return `${super.getResourceIdentifier()}|mode${this.mode}|name${this.name}`;
72
+ }
73
+
74
+ /**
75
+ * @param {string} name export name
76
+ * @param {CssGeneratorExportsConvention} convention convention of the export name
77
+ * @returns {string[]} convention results
78
+ */
79
+ getExportsConventionNames(name, convention) {
80
+ return cssExportConvention(name, convention);
81
+ }
82
+
83
+ /**
84
+ * Returns list of exports referenced by this dependency
85
+ * @param {ModuleGraph} moduleGraph module graph
86
+ * @param {RuntimeSpec} runtime the runtime for which the module is analysed
87
+ * @returns {ReferencedExports} referenced exports
88
+ */
89
+ getReferencedExports(moduleGraph, runtime) {
90
+ return [
91
+ {
92
+ name: [this.name],
93
+ canMangle: true
94
+ }
95
+ ];
96
+ }
97
+
98
+ /**
99
+ * Returns warnings
100
+ * @param {ModuleGraph} moduleGraph module graph
101
+ * @returns {WebpackError[] | null | undefined} warnings
102
+ */
103
+ getWarnings(moduleGraph) {
104
+ const module = moduleGraph.getModule(this);
105
+
106
+ if (
107
+ module &&
108
+ !moduleGraph.getExportsInfo(module).isExportProvided(this.name)
109
+ ) {
110
+ const error = new WebpackError(
111
+ `Referenced name "${this.name}" in "${this.userRequest}" not found`
112
+ );
113
+ error.module = module;
114
+
115
+ return [error];
116
+ }
117
+
118
+ return null;
42
119
  }
43
120
 
44
121
  /**
@@ -46,8 +123,11 @@ class CssIcssImportDependency extends ModuleDependency {
46
123
  */
47
124
  serialize(context) {
48
125
  const { write } = context;
49
- write(this.range);
50
- write(this.exportName);
126
+ write(this.name);
127
+ write(this.value);
128
+ write(this.interpolate);
129
+ write(this.exportMode);
130
+ write(this.exportType);
51
131
  super.serialize(context);
52
132
  }
53
133
 
@@ -56,14 +136,17 @@ class CssIcssImportDependency extends ModuleDependency {
56
136
  */
57
137
  deserialize(context) {
58
138
  const { read } = context;
59
- this.range = read();
60
- this.exportName = read();
139
+ this.name = read();
140
+ this.value = read();
141
+ this.interpolate = read();
142
+ this.exportMode = read();
143
+ this.exportType = read();
61
144
  super.deserialize(context);
62
145
  }
63
146
  }
64
147
 
65
148
  CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends (
66
- ModuleDependency.Template
149
+ CssImportDependency.Template
67
150
  ) {
68
151
  /**
69
152
  * @param {Dependency} dependency the dependency for which the template should be applied
@@ -73,42 +156,22 @@ CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends
73
156
  */
74
157
  apply(dependency, source, templateContext) {
75
158
  const dep = /** @type {CssIcssImportDependency} */ (dependency);
76
- const { range } = dep;
77
- const module =
78
- /** @type {Module} */
79
- (templateContext.moduleGraph.getModule(dep));
80
- let value;
81
-
82
- for (const item of module.dependencies) {
83
- if (
84
- item instanceof CssLocalIdentifierDependency &&
85
- dep.exportName === item.name
86
- ) {
87
- value = CssLocalIdentifierDependency.Template.getIdentifier(
88
- item,
89
- dep.exportName,
90
- {
91
- ...templateContext,
92
- module
93
- }
94
- );
95
- break;
96
- } else if (
97
- item instanceof CssIcssExportDependency &&
98
- dep.exportName === item.name
99
- ) {
100
- value = item.value;
101
- break;
102
- }
103
- }
104
159
 
105
- if (!value) {
106
- throw new Error(
107
- `Imported '${dep.exportName}' name from '${dep.request}' not found`
108
- );
160
+ if (dep.value) {
161
+ const { moduleGraph } = templateContext;
162
+ const module =
163
+ /** @type {CssModule} */
164
+ (moduleGraph.getModule(dep));
165
+ const CssIcssExportDependency = getCssIcssExportDependency();
166
+ const template = new CssIcssExportDependency.Template();
167
+ const originalName = dep.name;
168
+ const originalExportName = dep.value;
169
+ dep.value = originalName;
170
+ dep.name = originalExportName;
171
+ template.apply(dep, source, { ...templateContext, module });
172
+ dep.name = originalName;
173
+ dep.value = originalExportName;
109
174
  }
110
-
111
- source.replace(range[0], range[1], value);
112
175
  }
113
176
  };
114
177
 
@@ -5,7 +5,9 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { CSS_TYPE } = require("../ModuleSourceTypeConstants");
8
9
  const makeSerializable = require("../util/makeSerializable");
10
+ const CssIcssExportDependency = require("./CssIcssExportDependency");
9
11
  const NullDependency = require("./NullDependency");
10
12
 
11
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -24,23 +26,21 @@ const NullDependency = require("./NullDependency");
24
26
  class CssIcssSymbolDependency extends NullDependency {
25
27
  /**
26
28
  * @param {string} name name
27
- * @param {string} value value
29
+ * @param {string} symbol symbol
28
30
  * @param {Range} range range
31
+ * @param {boolean=} isReference true when is reference, otherwise false
29
32
  */
30
- constructor(name, value, range) {
33
+ constructor(name, symbol, range, isReference) {
31
34
  super();
32
35
  this.name = name;
33
- this.value = value;
36
+ this.symbol = symbol;
34
37
  this.range = range;
38
+ this.isReference = isReference;
35
39
  this._hashUpdate = undefined;
36
40
  }
37
41
 
38
42
  get type() {
39
- return "css @value identifier";
40
- }
41
-
42
- get category() {
43
- return "self";
43
+ return "css symbol identifier";
44
44
  }
45
45
 
46
46
  /**
@@ -56,23 +56,6 @@ class CssIcssSymbolDependency extends NullDependency {
56
56
  hash.update(this._hashUpdate);
57
57
  }
58
58
 
59
- /**
60
- * Returns the exported names
61
- * @param {ModuleGraph} moduleGraph module graph
62
- * @returns {ExportsSpec | undefined} export names
63
- */
64
- getExports(moduleGraph) {
65
- return {
66
- exports: [
67
- {
68
- name: this.name,
69
- canMangle: true
70
- }
71
- ],
72
- dependencies: undefined
73
- };
74
- }
75
-
76
59
  /**
77
60
  * Returns list of exports referenced by this dependency
78
61
  * @param {ModuleGraph} moduleGraph module graph
@@ -80,7 +63,7 @@ class CssIcssSymbolDependency extends NullDependency {
80
63
  * @returns {ReferencedExports} referenced exports
81
64
  */
82
65
  getReferencedExports(moduleGraph, runtime) {
83
- return [[this.name]];
66
+ return [[this.symbol]];
84
67
  }
85
68
 
86
69
  /**
@@ -89,8 +72,10 @@ class CssIcssSymbolDependency extends NullDependency {
89
72
  serialize(context) {
90
73
  const { write } = context;
91
74
  write(this.name);
75
+ write(this.symbol);
92
76
  write(this.value);
93
77
  write(this.range);
78
+ write(this.isReference);
94
79
  super.serialize(context);
95
80
  }
96
81
 
@@ -100,13 +85,15 @@ class CssIcssSymbolDependency extends NullDependency {
100
85
  deserialize(context) {
101
86
  const { read } = context;
102
87
  this.name = read();
88
+ this.symbol = read();
103
89
  this.value = read();
104
90
  this.range = read();
91
+ this.isReference = read();
105
92
  super.deserialize(context);
106
93
  }
107
94
  }
108
95
 
109
- CssIcssSymbolDependency.Template = class CssValueAtRuleDependencyTemplate extends (
96
+ CssIcssSymbolDependency.Template = class CssIcssSymbolDependencyTemplate extends (
110
97
  NullDependency.Template
111
98
  ) {
112
99
  /**
@@ -115,12 +102,23 @@ CssIcssSymbolDependency.Template = class CssValueAtRuleDependencyTemplate extend
115
102
  * @param {DependencyTemplateContext} templateContext the context object
116
103
  * @returns {void}
117
104
  */
118
- apply(dependency, source, { cssData }) {
119
- const dep = /** @type {CssIcssSymbolDependency} */ (dependency);
120
-
121
- source.replace(dep.range[0], dep.range[1] - 1, dep.value);
122
-
123
- cssData.exports.set(dep.name, dep.value);
105
+ apply(dependency, source, templateContext) {
106
+ if (templateContext.type === CSS_TYPE) {
107
+ const dep = /** @type {CssIcssSymbolDependency} */ (dependency);
108
+ /** @type {string | undefined} */
109
+ const value = dep.isReference
110
+ ? CssIcssExportDependency.Template.findReference(
111
+ dep.symbol,
112
+ templateContext
113
+ )
114
+ : dep.symbol;
115
+
116
+ if (!value) {
117
+ return;
118
+ }
119
+
120
+ source.replace(dep.range[0], dep.range[1] - 1, value);
121
+ }
124
122
  }
125
123
  };
126
124
 
@@ -10,7 +10,7 @@ const ModuleDependency = require("./ModuleDependency");
10
10
 
11
11
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
12
  /** @typedef {import("../Dependency")} Dependency */
13
- /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
13
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
14
14
  /** @typedef {import("../css/CssParser").Range} Range */
15
15
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
16
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -21,13 +21,15 @@ class CssImportDependency extends ModuleDependency {
21
21
  * \@import url("landscape.css") layer(forms) screen and (orientation: landscape) screen and (orientation: landscape);
22
22
  * @param {string} request request
23
23
  * @param {Range} range range of the argument
24
- * @param {string | undefined} layer layer
25
- * @param {string | undefined} supports list of supports conditions
26
- * @param {string | undefined} media list of media conditions
24
+ * @param {"local" | "global"=} mode mode of the parsed CSS
25
+ * @param {string=} layer layer
26
+ * @param {string=} supports list of supports conditions
27
+ * @param {string=} media list of media conditions
27
28
  */
28
- constructor(request, range, layer, supports, media) {
29
+ constructor(request, range, mode, layer, supports, media) {
29
30
  super(request);
30
31
  this.range = range;
32
+ this.mode = mode;
31
33
  this.layer = layer;
32
34
  this.supports = supports;
33
35
  this.media = media;
@@ -38,7 +40,7 @@ class CssImportDependency extends ModuleDependency {
38
40
  }
39
41
 
40
42
  get category() {
41
- return "css-import";
43
+ return `css-import${this.mode ? `-${this.mode}-module` : ""}`;
42
44
  }
43
45
 
44
46
  /**
@@ -47,6 +49,10 @@ class CssImportDependency extends ModuleDependency {
47
49
  getResourceIdentifier() {
48
50
  let str = `context${this._context || ""}|module${this.request}`;
49
51
 
52
+ if (this.mode) {
53
+ str += `|mode${this.mode}`;
54
+ }
55
+
50
56
  if (this.layer) {
51
57
  str += `|layer${this.layer}`;
52
58
  }
@@ -67,6 +73,8 @@ class CssImportDependency extends ModuleDependency {
67
73
  */
68
74
  serialize(context) {
69
75
  const { write } = context;
76
+ write(this.range);
77
+ write(this.mode);
70
78
  write(this.layer);
71
79
  write(this.supports);
72
80
  write(this.media);
@@ -78,6 +86,8 @@ class CssImportDependency extends ModuleDependency {
78
86
  */
79
87
  deserialize(context) {
80
88
  const { read } = context;
89
+ this.range = read();
90
+ this.mode = read();
81
91
  this.layer = read();
82
92
  this.supports = read();
83
93
  this.media = read();
@@ -95,6 +105,7 @@ CssImportDependency.Template = class CssImportDependencyTemplate extends (
95
105
  * @returns {void}
96
106
  */
97
107
  apply(dependency, source, templateContext) {
108
+ if (templateContext.type === "javascript") return;
98
109
  const dep = /** @type {CssImportDependency} */ (dependency);
99
110
 
100
111
  source.replace(dep.range[0], dep.range[1] - 1, "");
@@ -13,7 +13,7 @@ const ModuleDependency = require("./ModuleDependency");
13
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
14
  /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
15
15
  /** @typedef {import("../Dependency")} Dependency */
16
- /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
17
17
  /** @typedef {import("../Module")} Module */
18
18
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
19
19
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
@@ -118,8 +118,9 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
118
118
  apply(
119
119
  dependency,
120
120
  source,
121
- { moduleGraph, runtimeTemplate, codeGenerationResults }
121
+ { type, moduleGraph, runtimeTemplate, codeGenerationResults }
122
122
  ) {
123
+ if (type === "javascript") return;
123
124
  const dep = /** @type {CssUrlDependency} */ (dependency);
124
125
  const module = /** @type {Module} */ (moduleGraph.getModule(dep));
125
126
 
@@ -6,13 +6,13 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
9
- /** @typedef {import("../Parser").ParserState} ParserState */
9
+ /** @typedef {import("../javascript/JavascriptParser").JavascriptParserState} JavascriptParserState */
10
10
 
11
- /** @type {WeakMap<ParserState, boolean>} */
11
+ /** @type {WeakMap<JavascriptParserState, boolean>} */
12
12
  const parserStateExportsState = new WeakMap();
13
13
 
14
14
  /**
15
- * @param {ParserState} parserState parser state
15
+ * @param {JavascriptParserState} parserState parser state
16
16
  * @returns {void}
17
17
  */
18
18
  module.exports.bailout = (parserState) => {
@@ -26,7 +26,7 @@ module.exports.bailout = (parserState) => {
26
26
  };
27
27
 
28
28
  /**
29
- * @param {ParserState} parserState parser state
29
+ * @param {JavascriptParserState} parserState parser state
30
30
  * @returns {void}
31
31
  */
32
32
  module.exports.enable = (parserState) => {
@@ -41,7 +41,7 @@ module.exports.enable = (parserState) => {
41
41
  };
42
42
 
43
43
  /**
44
- * @param {ParserState} parserState parser state
44
+ * @param {JavascriptParserState} parserState parser state
45
45
  * @returns {boolean} true, when enabled
46
46
  */
47
47
  module.exports.isEnabled = (parserState) => {
@@ -50,7 +50,7 @@ module.exports.isEnabled = (parserState) => {
50
50
  };
51
51
 
52
52
  /**
53
- * @param {ParserState} parserState parser state
53
+ * @param {JavascriptParserState} parserState parser state
54
54
  * @returns {void}
55
55
  */
56
56
  module.exports.setDynamic = (parserState) => {
@@ -61,7 +61,7 @@ module.exports.setDynamic = (parserState) => {
61
61
  };
62
62
 
63
63
  /**
64
- * @param {ParserState} parserState parser state
64
+ * @param {JavascriptParserState} parserState parser state
65
65
  * @returns {void}
66
66
  */
67
67
  module.exports.setFlagged = (parserState) => {
@@ -13,17 +13,19 @@ const ExternalModuleInitFragment = require("./ExternalModuleInitFragment");
13
13
  /** @typedef {import("../Dependency")} Dependency */
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
15
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
16
+ /** @typedef {import("../dependencies/ExternalModuleInitFragment").ArrayImportSpecifiers} ArrayImportSpecifiers */
16
17
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17
18
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
18
19
 
19
20
  class ExternalModuleDependency extends CachedConstDependency {
20
21
  /**
21
22
  * @param {string} module module
22
- * @param {{ name: string, value: string }[]} importSpecifiers import specifiers
23
+ * @param {ArrayImportSpecifiers} importSpecifiers import specifiers
23
24
  * @param {string | undefined} defaultImport default import
24
25
  * @param {string} expression expression
25
- * @param {Range} range range
26
+ * @param {Range | null} range range
26
27
  * @param {string} identifier identifier
28
+ * @param {number=} place place where we inject the expression
27
29
  */
28
30
  constructor(
29
31
  module,
@@ -31,9 +33,10 @@ class ExternalModuleDependency extends CachedConstDependency {
31
33
  defaultImport,
32
34
  expression,
33
35
  range,
34
- identifier
36
+ identifier,
37
+ place = CachedConstDependency.PLACE_MODULE
35
38
  ) {
36
- super(expression, range, identifier);
39
+ super(expression, range, identifier, place);
37
40
 
38
41
  this.importedModule = module;
39
42
  this.specifiers = importSpecifiers;
@@ -12,6 +12,7 @@ const makeSerializable = require("../util/makeSerializable");
12
12
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
13
13
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
14
14
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
+ /** @typedef {{ name: string, value?: string }[]} ArrayImportSpecifiers */
15
16
  /** @typedef {Map<string, Set<string>>} ImportSpecifiers */
16
17
 
17
18
  /**
@@ -20,7 +21,7 @@ const makeSerializable = require("../util/makeSerializable");
20
21
  class ExternalModuleInitFragment extends InitFragment {
21
22
  /**
22
23
  * @param {string} importedModule imported module
23
- * @param {{ name: string, value?: string }[] | ImportSpecifiers} specifiers import specifiers
24
+ * @param {ArrayImportSpecifiers | ImportSpecifiers} specifiers import specifiers
24
25
  * @param {string=} defaultImport default import
25
26
  */
26
27
  constructor(importedModule, specifiers, defaultImport) {
@@ -99,7 +100,7 @@ class ExternalModuleInitFragment extends InitFragment {
99
100
 
100
101
  return `import ${importsString} from ${JSON.stringify(
101
102
  this.importedModule
102
- )};`;
103
+ )};\n`;
103
104
  }
104
105
 
105
106
  /**
@@ -0,0 +1,96 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const DependencyTemplate = require("../DependencyTemplate");
9
+ const makeSerializable = require("../util/makeSerializable");
10
+ const ExternalModuleInitFragment = require("./ExternalModuleInitFragment");
11
+ const NullDependency = require("./NullDependency");
12
+
13
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
+ /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
17
+ /** @typedef {import("../dependencies/ExternalModuleInitFragment").ArrayImportSpecifiers} ArrayImportSpecifiers */
18
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
+
21
+ class ExternalModuleInitFragmentDependency extends NullDependency {
22
+ /**
23
+ * @param {string} module module
24
+ * @param {ArrayImportSpecifiers} importSpecifiers import specifiers
25
+ * @param {string | undefined} defaultImport default import
26
+ */
27
+ constructor(module, importSpecifiers, defaultImport) {
28
+ super();
29
+ this.importedModule = module;
30
+ this.specifiers = importSpecifiers;
31
+ this.default = defaultImport;
32
+ }
33
+
34
+ /**
35
+ * @returns {string} hash update
36
+ */
37
+ _createHashUpdate() {
38
+ return `${this.importedModule}${JSON.stringify(this.specifiers)}${
39
+ this.default || "null"
40
+ }`;
41
+ }
42
+
43
+ /**
44
+ * @param {ObjectSerializerContext} context context
45
+ */
46
+ serialize(context) {
47
+ const { write } = context;
48
+ write(this.importedModule);
49
+ write(this.specifiers);
50
+ write(this.default);
51
+ }
52
+
53
+ /**
54
+ * @param {ObjectDeserializerContext} context context
55
+ */
56
+ deserialize(context) {
57
+ const { read } = context;
58
+ this.importedModule = read();
59
+ this.specifiers = read();
60
+ this.default = read();
61
+ }
62
+ }
63
+
64
+ makeSerializable(
65
+ ExternalModuleInitFragmentDependency,
66
+ "webpack/lib/dependencies/ExternalModuleConstDependency"
67
+ );
68
+
69
+ ExternalModuleInitFragmentDependency.Template = class ExternalModuleConstDependencyTemplate extends (
70
+ DependencyTemplate
71
+ ) {
72
+ /**
73
+ * @param {Dependency} dependency the dependency for which the template should be applied
74
+ * @param {ReplaceSource} source the current replace source which can be modified
75
+ * @param {DependencyTemplateContext} templateContext the context object
76
+ * @returns {void}
77
+ */
78
+ apply(dependency, source, templateContext) {
79
+ const dep =
80
+ /** @type {ExternalModuleInitFragmentDependency} */
81
+ (dependency);
82
+ const { chunkInitFragments, runtimeTemplate } = templateContext;
83
+
84
+ chunkInitFragments.push(
85
+ new ExternalModuleInitFragment(
86
+ `${runtimeTemplate.supportNodePrefixForCoreModules() ? "node:" : ""}${
87
+ dep.importedModule
88
+ }`,
89
+ dep.specifiers,
90
+ dep.default
91
+ )
92
+ );
93
+ }
94
+ };
95
+
96
+ module.exports = ExternalModuleInitFragmentDependency;
@@ -9,6 +9,7 @@ const Template = require("../Template");
9
9
  const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
10
10
  const makeSerializable = require("../util/makeSerializable");
11
11
  const HarmonyImportDependency = require("./HarmonyImportDependency");
12
+ const { ImportPhaseUtils } = require("./ImportPhase");
12
13
  const NullDependency = require("./NullDependency");
13
14
 
14
15
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -120,7 +121,11 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
120
121
  for (const d of module.dependencies) {
121
122
  if (deferDependency && noDeferredDependency) break;
122
123
  if (isRelatedHarmonyImportDependency(dependency, d)) {
123
- if (/** @type {HarmonyImportDependency} */ (d).defer) {
124
+ if (
125
+ ImportPhaseUtils.isDefer(
126
+ /** @type {HarmonyImportDependency} */ (d).phase
127
+ )
128
+ ) {
124
129
  deferDependency = /** @type {HarmonyImportDependency} */ (d);
125
130
  } else {
126
131
  noDeferredDependency = /** @type {HarmonyImportDependency} */ (d);