webpack 5.98.0 → 5.99.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.
- package/README.md +7 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +287 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
package/lib/container/options.js
CHANGED
@@ -19,9 +19,9 @@
|
|
19
19
|
* @template T
|
20
20
|
* @template N
|
21
21
|
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
22
|
-
* @param {
|
23
|
-
* @param {
|
24
|
-
* @param {
|
22
|
+
* @param {(item: string | string[], itemOrKey: string) => N} normalizeSimple normalize a simple item
|
23
|
+
* @param {(value: T, key: string) => N} normalizeOptions normalize a complex item
|
24
|
+
* @param {(item: string, normalized: N) => void} fn processing function
|
25
25
|
* @returns {void}
|
26
26
|
*/
|
27
27
|
const process = (options, normalizeSimple, normalizeOptions, fn) => {
|
@@ -66,8 +66,8 @@ const process = (options, normalizeSimple, normalizeOptions, fn) => {
|
|
66
66
|
* @template T
|
67
67
|
* @template R
|
68
68
|
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
69
|
-
* @param {
|
70
|
-
* @param {
|
69
|
+
* @param {(item: string | string[], itemOrKey: string) => R} normalizeSimple normalize a simple item
|
70
|
+
* @param {(value: T, key: string) => R} normalizeOptions normalize a complex item
|
71
71
|
* @returns {[string, R][]} parsed options
|
72
72
|
*/
|
73
73
|
const parseOptions = (options, normalizeSimple, normalizeOptions) => {
|
package/lib/css/CssGenerator.js
CHANGED
@@ -11,7 +11,10 @@ const Generator = require("../Generator");
|
|
11
11
|
const InitFragment = require("../InitFragment");
|
12
12
|
const {
|
13
13
|
JS_AND_CSS_EXPORT_TYPES,
|
14
|
-
JS_AND_CSS_TYPES
|
14
|
+
JS_AND_CSS_TYPES,
|
15
|
+
CSS_TYPES,
|
16
|
+
JS_TYPE,
|
17
|
+
CSS_TYPE
|
15
18
|
} = require("../ModuleSourceTypesConstants");
|
16
19
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
17
20
|
const Template = require("../Template");
|
@@ -26,21 +29,26 @@ const Template = require("../Template");
|
|
26
29
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
27
30
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
28
31
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
32
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
33
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
29
34
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
30
35
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
36
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
31
37
|
/** @typedef {import("../NormalModule")} NormalModule */
|
32
38
|
/** @typedef {import("../util/Hash")} Hash */
|
33
39
|
|
34
40
|
class CssGenerator extends Generator {
|
35
41
|
/**
|
36
42
|
* @param {CssAutoGeneratorOptions | CssGlobalGeneratorOptions | CssModuleGeneratorOptions} options options
|
43
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
37
44
|
*/
|
38
|
-
constructor(options) {
|
45
|
+
constructor(options, moduleGraph) {
|
39
46
|
super();
|
40
47
|
this.convention = options.exportsConvention;
|
41
48
|
this.localIdentName = options.localIdentName;
|
42
49
|
this.exportsOnly = options.exportsOnly;
|
43
50
|
this.esModule = options.esModule;
|
51
|
+
this._moduleGraph = moduleGraph;
|
44
52
|
}
|
45
53
|
|
46
54
|
/**
|
@@ -71,7 +79,7 @@ class CssGenerator extends Generator {
|
|
71
79
|
const initFragments = [];
|
72
80
|
/** @type {CssData} */
|
73
81
|
const cssData = {
|
74
|
-
esModule: this.esModule,
|
82
|
+
esModule: /** @type {boolean} */ (this.esModule),
|
75
83
|
exports: new Map()
|
76
84
|
};
|
77
85
|
|
@@ -131,7 +139,8 @@ class CssGenerator extends Generator {
|
|
131
139
|
|
132
140
|
switch (generateContext.type) {
|
133
141
|
case "javascript": {
|
134
|
-
|
142
|
+
/** @type {BuildInfo} */
|
143
|
+
(module.buildInfo).cssData = cssData;
|
135
144
|
|
136
145
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
137
146
|
|
@@ -167,6 +176,13 @@ class CssGenerator extends Generator {
|
|
167
176
|
return source;
|
168
177
|
}
|
169
178
|
|
179
|
+
if (
|
180
|
+
cssData.exports.size === 0 &&
|
181
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).isCSSModule)
|
182
|
+
) {
|
183
|
+
return new RawSource("");
|
184
|
+
}
|
185
|
+
|
170
186
|
const needNsObj =
|
171
187
|
this.esModule &&
|
172
188
|
generateContext.moduleGraph
|
@@ -203,6 +219,29 @@ class CssGenerator extends Generator {
|
|
203
219
|
|
204
220
|
return InitFragment.addToSource(source, initFragments, generateContext);
|
205
221
|
}
|
222
|
+
default:
|
223
|
+
return null;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
/**
|
228
|
+
* @param {Error} error the error
|
229
|
+
* @param {NormalModule} module module for which the code should be generated
|
230
|
+
* @param {GenerateContext} generateContext context for generate
|
231
|
+
* @returns {Source | null} generated code
|
232
|
+
*/
|
233
|
+
generateError(error, module, generateContext) {
|
234
|
+
switch (generateContext.type) {
|
235
|
+
case "javascript": {
|
236
|
+
return new RawSource(
|
237
|
+
`throw new Error(${JSON.stringify(error.message)});`
|
238
|
+
);
|
239
|
+
}
|
240
|
+
case "css": {
|
241
|
+
return new RawSource(`/**\n ${error.message} \n**/`);
|
242
|
+
}
|
243
|
+
default:
|
244
|
+
return null;
|
206
245
|
}
|
207
246
|
}
|
208
247
|
|
@@ -212,7 +251,22 @@ class CssGenerator extends Generator {
|
|
212
251
|
*/
|
213
252
|
getTypes(module) {
|
214
253
|
// TODO, find a better way to prevent the original module from being removed after concatenation, maybe it is a bug
|
215
|
-
|
254
|
+
if (this.exportsOnly) {
|
255
|
+
return JS_AND_CSS_EXPORT_TYPES;
|
256
|
+
}
|
257
|
+
const sourceTypes = new Set();
|
258
|
+
const connections = this._moduleGraph.getIncomingConnections(module);
|
259
|
+
for (const connection of connections) {
|
260
|
+
if (!connection.originModule) {
|
261
|
+
continue;
|
262
|
+
}
|
263
|
+
if (connection.originModule.type.split("/")[0] !== CSS_TYPE)
|
264
|
+
sourceTypes.add(JS_TYPE);
|
265
|
+
}
|
266
|
+
if (sourceTypes.has(JS_TYPE)) {
|
267
|
+
return JS_AND_CSS_TYPES;
|
268
|
+
}
|
269
|
+
return CSS_TYPES;
|
216
270
|
}
|
217
271
|
|
218
272
|
/**
|
@@ -223,11 +277,17 @@ class CssGenerator extends Generator {
|
|
223
277
|
getSize(module, type) {
|
224
278
|
switch (type) {
|
225
279
|
case "javascript": {
|
226
|
-
|
280
|
+
const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData;
|
281
|
+
if (!cssData) {
|
227
282
|
return 42;
|
228
283
|
}
|
229
|
-
|
230
|
-
|
284
|
+
if (cssData.exports.size === 0) {
|
285
|
+
if (/** @type {BuildMeta} */ (module.buildMeta).isCSSModule) {
|
286
|
+
return 42;
|
287
|
+
}
|
288
|
+
return 0;
|
289
|
+
}
|
290
|
+
const exports = cssData.exports;
|
231
291
|
const stringifiedExports = JSON.stringify(
|
232
292
|
Array.from(exports).reduce((obj, [key, value]) => {
|
233
293
|
obj[key] = value;
|
@@ -246,6 +306,8 @@ class CssGenerator extends Generator {
|
|
246
306
|
|
247
307
|
return originalSource.size();
|
248
308
|
}
|
309
|
+
default:
|
310
|
+
return 0;
|
249
311
|
}
|
250
312
|
}
|
251
313
|
|
@@ -254,7 +316,7 @@ class CssGenerator extends Generator {
|
|
254
316
|
* @param {UpdateHashContext} updateHashContext context for updating hash
|
255
317
|
*/
|
256
318
|
updateHash(hash, { module }) {
|
257
|
-
hash.update(this.esModule.toString());
|
319
|
+
hash.update(/** @type {boolean} */ (this.esModule).toString());
|
258
320
|
}
|
259
321
|
}
|
260
322
|
|
@@ -23,6 +23,7 @@ const {
|
|
23
23
|
CSS_MODULE_TYPE_MODULE,
|
24
24
|
CSS_MODULE_TYPE_AUTO
|
25
25
|
} = require("../ModuleTypeConstants");
|
26
|
+
const NormalModule = require("../NormalModule");
|
26
27
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
27
28
|
const SelfModuleFactory = require("../SelfModuleFactory");
|
28
29
|
const Template = require("../Template");
|
@@ -42,6 +43,7 @@ const createHash = require("../util/createHash");
|
|
42
43
|
const { getUndoPath } = require("../util/identifier");
|
43
44
|
const memoize = require("../util/memoize");
|
44
45
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
46
|
+
const removeBOM = require("../util/removeBOM");
|
45
47
|
const CssGenerator = require("./CssGenerator");
|
46
48
|
const CssParser = require("./CssParser");
|
47
49
|
|
@@ -54,6 +56,7 @@ const CssParser = require("./CssParser");
|
|
54
56
|
/** @typedef {import("../Compiler")} Compiler */
|
55
57
|
/** @typedef {import("../CssModule").Inheritance} Inheritance */
|
56
58
|
/** @typedef {import("../Module")} Module */
|
59
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
57
60
|
/** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */
|
58
61
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
59
62
|
/** @typedef {import("../util/Hash")} Hash */
|
@@ -92,7 +95,7 @@ const getCssLoadingRuntimeModule = memoize(() =>
|
|
92
95
|
|
93
96
|
/**
|
94
97
|
* @param {string} name name
|
95
|
-
* @returns {{oneOf: [{$ref: string}], definitions:
|
98
|
+
* @returns {{ oneOf: [{ $ref: string }], definitions: import("../../schemas/WebpackOptions.json")["definitions"] }} schema
|
96
99
|
*/
|
97
100
|
const getSchema = name => {
|
98
101
|
const { definitions } = require("../../schemas/WebpackOptions.json");
|
@@ -298,7 +301,10 @@ class CssModulesPlugin {
|
|
298
301
|
.tap(PLUGIN_NAME, generatorOptions => {
|
299
302
|
validateGeneratorOptions[type](generatorOptions);
|
300
303
|
|
301
|
-
return new CssGenerator(
|
304
|
+
return new CssGenerator(
|
305
|
+
generatorOptions,
|
306
|
+
compilation.moduleGraph
|
307
|
+
);
|
302
308
|
});
|
303
309
|
normalModuleFactory.hooks.createModuleClass
|
304
310
|
.for(type)
|
@@ -360,13 +366,28 @@ class CssModulesPlugin {
|
|
360
366
|
|
361
367
|
return new CssModule(createData);
|
362
368
|
});
|
369
|
+
|
370
|
+
NormalModule.getCompilationHooks(compilation).processResult.tap(
|
371
|
+
PLUGIN_NAME,
|
372
|
+
(result, module) => {
|
373
|
+
if (module.type === type) {
|
374
|
+
const [source, ...rest] = result;
|
375
|
+
|
376
|
+
return [removeBOM(source), ...rest];
|
377
|
+
}
|
378
|
+
|
379
|
+
return result;
|
380
|
+
}
|
381
|
+
);
|
363
382
|
}
|
364
383
|
|
365
384
|
JavascriptModulesPlugin.getCompilationHooks(
|
366
385
|
compilation
|
367
386
|
).renderModuleContent.tap(PLUGIN_NAME, (source, module) => {
|
368
387
|
if (module instanceof CssModule && module.hot) {
|
369
|
-
const exports =
|
388
|
+
const exports =
|
389
|
+
/** @type {BuildInfo} */
|
390
|
+
(module.buildInfo).cssData.exports;
|
370
391
|
const stringifiedExports = JSON.stringify(
|
371
392
|
JSON.stringify(
|
372
393
|
Array.from(exports).reduce((obj, [key, value]) => {
|
@@ -390,6 +411,8 @@ class CssModulesPlugin {
|
|
390
411
|
|
391
412
|
return new ConcatSource(source, "\n", new RawSource(hmrCode));
|
392
413
|
}
|
414
|
+
|
415
|
+
return source;
|
393
416
|
});
|
394
417
|
const orderedCssModulesPerChunk = new WeakMap();
|
395
418
|
compilation.hooks.afterCodeGeneration.tap(PLUGIN_NAME, () => {
|
@@ -475,7 +498,9 @@ class CssModulesPlugin {
|
|
475
498
|
chunk,
|
476
499
|
chunkGraph,
|
477
500
|
codeGenerationResults,
|
478
|
-
uniqueName:
|
501
|
+
uniqueName:
|
502
|
+
/** @type {string} */
|
503
|
+
(compilation.outputOptions.uniqueName),
|
479
504
|
undoPath,
|
480
505
|
modules,
|
481
506
|
runtimeTemplate
|
@@ -718,7 +743,7 @@ class CssModulesPlugin {
|
|
718
743
|
}
|
719
744
|
|
720
745
|
/**
|
721
|
-
* @param {CssModule}
|
746
|
+
* @param {CssModule} module css module
|
722
747
|
* @param {ChunkRenderContext} renderContext options object
|
723
748
|
* @param {CompilationHooks} hooks hooks
|
724
749
|
* @returns {Source} css module source
|
package/lib/css/CssParser.js
CHANGED
@@ -283,13 +283,17 @@ const eatUntilSemi = walkCssTokens.eatUntil(";");
|
|
283
283
|
const eatUntilLeftCurly = walkCssTokens.eatUntil("{");
|
284
284
|
const eatSemi = walkCssTokens.eatUntil(";");
|
285
285
|
|
286
|
+
/**
|
287
|
+
* @typedef {object} CssParserOptions
|
288
|
+
* @property {boolean=} importOption need handle `@import`
|
289
|
+
* @property {boolean=} url need handle URLs
|
290
|
+
* @property {("pure" | "global" | "local" | "auto")=} defaultMode default mode
|
291
|
+
* @property {boolean=} namedExports is named exports
|
292
|
+
*/
|
293
|
+
|
286
294
|
class CssParser extends Parser {
|
287
295
|
/**
|
288
|
-
* @param {
|
289
|
-
* @param {boolean=} options.importOption need handle `@import`
|
290
|
-
* @param {boolean=} options.url need handle URLs
|
291
|
-
* @param {("pure" | "global" | "local" | "auto")=} options.defaultMode default mode
|
292
|
-
* @param {boolean=} options.namedExports is named exports
|
296
|
+
* @param {CssParserOptions} [options] options
|
293
297
|
*/
|
294
298
|
constructor({
|
295
299
|
defaultMode = "pure",
|
@@ -357,6 +361,9 @@ class CssParser extends Parser {
|
|
357
361
|
|
358
362
|
const isModules = mode === "global" || mode === "local";
|
359
363
|
|
364
|
+
/** @type {BuildMeta} */
|
365
|
+
(module.buildMeta).isCSSModule = isModules;
|
366
|
+
|
360
367
|
const locConverter = new LocConverter(source);
|
361
368
|
|
362
369
|
/** @type {number} */
|
@@ -379,7 +386,8 @@ class CssParser extends Parser {
|
|
379
386
|
let lastIdentifier;
|
380
387
|
/** @type {Set<string>} */
|
381
388
|
const declaredCssVariables = new Set();
|
382
|
-
/** @
|
389
|
+
/** @typedef {{ path?: string, value: string }} IcssDefinition */
|
390
|
+
/** @type {Map<string, IcssDefinition>} */
|
383
391
|
const icssDefinitions = new Map();
|
384
392
|
|
385
393
|
/**
|
@@ -447,6 +455,7 @@ class CssParser extends Parser {
|
|
447
455
|
*/
|
448
456
|
const parseImportOrExport = (type, input, pos) => {
|
449
457
|
pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
|
458
|
+
/** @type {string | undefined} */
|
450
459
|
let importPath;
|
451
460
|
if (type === 0) {
|
452
461
|
let cc = input.charCodeAt(pos);
|
@@ -517,7 +526,9 @@ class CssParser extends Parser {
|
|
517
526
|
/** @type {undefined | 0 | 1 | 2} */
|
518
527
|
let scope;
|
519
528
|
|
520
|
-
/** @
|
529
|
+
/** @typedef {[number, number]} Name */
|
530
|
+
|
531
|
+
/** @type {Name | undefined} */
|
521
532
|
let name;
|
522
533
|
/** @type {number | undefined} */
|
523
534
|
let value;
|
@@ -537,10 +548,11 @@ class CssParser extends Parser {
|
|
537
548
|
balanced--;
|
538
549
|
|
539
550
|
if (scope === 2) {
|
551
|
+
const [nameStart, nameEnd] = /** @type {Name} */ (name);
|
540
552
|
createDep(
|
541
|
-
input.slice(
|
553
|
+
input.slice(nameStart, nameEnd),
|
542
554
|
input.slice(value, end - 1).trim(),
|
543
|
-
|
555
|
+
nameEnd,
|
544
556
|
end - 1
|
545
557
|
);
|
546
558
|
scope = 0;
|
@@ -571,10 +583,11 @@ class CssParser extends Parser {
|
|
571
583
|
},
|
572
584
|
semicolon: (input, _start, end) => {
|
573
585
|
if (scope === 2) {
|
586
|
+
const [nameStart, nameEnd] = /** @type {Name} */ (name);
|
574
587
|
createDep(
|
575
|
-
input.slice(
|
588
|
+
input.slice(nameStart, nameEnd),
|
576
589
|
input.slice(value, end - 1),
|
577
|
-
|
590
|
+
nameEnd,
|
578
591
|
end - 1
|
579
592
|
);
|
580
593
|
scope = 0;
|
@@ -986,7 +999,9 @@ class CssParser extends Parser {
|
|
986
999
|
}
|
987
1000
|
|
988
1001
|
if (icssDefinitions.has(value)) {
|
989
|
-
const def =
|
1002
|
+
const def =
|
1003
|
+
/** @type {IcssDefinition} */
|
1004
|
+
(icssDefinitions.get(value));
|
990
1005
|
|
991
1006
|
value = def.value;
|
992
1007
|
}
|
@@ -1068,13 +1083,18 @@ class CssParser extends Parser {
|
|
1068
1083
|
},
|
1069
1084
|
identifier: (input, start, end) => {
|
1070
1085
|
if (isModules) {
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1086
|
+
const name = input.slice(start, end);
|
1087
|
+
|
1088
|
+
if (icssDefinitions.has(name)) {
|
1089
|
+
let { path, value } =
|
1090
|
+
/** @type {IcssDefinition} */
|
1091
|
+
(icssDefinitions.get(name));
|
1074
1092
|
|
1075
1093
|
if (path) {
|
1076
1094
|
if (icssDefinitions.has(path)) {
|
1077
|
-
const definition =
|
1095
|
+
const definition =
|
1096
|
+
/** @type {IcssDefinition} */
|
1097
|
+
(icssDefinitions.get(path));
|
1078
1098
|
|
1079
1099
|
path = definition.value.slice(1, -1);
|
1080
1100
|
}
|
@@ -1555,7 +1575,7 @@ class CssParser extends Parser {
|
|
1555
1575
|
|
1556
1576
|
/**
|
1557
1577
|
* @param {Range} range range of the comment
|
1558
|
-
* @returns {{ options: Record<string,
|
1578
|
+
* @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: Comment })[] | null }} result
|
1559
1579
|
*/
|
1560
1580
|
parseCommentOptions(range) {
|
1561
1581
|
const comments = this.getComments(range);
|
package/lib/css/walkCssTokens.js
CHANGED
@@ -7,25 +7,25 @@
|
|
7
7
|
|
8
8
|
/**
|
9
9
|
* @typedef {object} CssTokenCallbacks
|
10
|
-
* @property {(
|
11
|
-
* @property {(
|
12
|
-
* @property {(
|
13
|
-
* @property {(
|
14
|
-
* @property {(
|
15
|
-
* @property {(
|
16
|
-
* @property {(
|
17
|
-
* @property {(
|
18
|
-
* @property {(
|
19
|
-
* @property {(
|
20
|
-
* @property {(
|
21
|
-
* @property {(
|
22
|
-
* @property {(
|
23
|
-
* @property {(
|
24
|
-
* @property {(
|
25
|
-
* @property {(
|
10
|
+
* @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url
|
11
|
+
* @property {((input: string, start: number, end: number) => number)=} comment
|
12
|
+
* @property {((input: string, start: number, end: number) => number)=} string
|
13
|
+
* @property {((input: string, start: number, end: number) => number)=} leftParenthesis
|
14
|
+
* @property {((input: string, start: number, end: number) => number)=} rightParenthesis
|
15
|
+
* @property {((input: string, start: number, end: number) => number)=} function
|
16
|
+
* @property {((input: string, start: number, end: number) => number)=} colon
|
17
|
+
* @property {((input: string, start: number, end: number) => number)=} atKeyword
|
18
|
+
* @property {((input: string, start: number, end: number) => number)=} delim
|
19
|
+
* @property {((input: string, start: number, end: number) => number)=} identifier
|
20
|
+
* @property {((input: string, start: number, end: number, isId: boolean) => number)=} hash
|
21
|
+
* @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
|
22
|
+
* @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
|
23
|
+
* @property {((input: string, start: number, end: number) => number)=} semicolon
|
24
|
+
* @property {((input: string, start: number, end: number) => number)=} comma
|
25
|
+
* @property {(() => boolean)=} needTerminate
|
26
26
|
*/
|
27
27
|
|
28
|
-
/** @typedef {
|
28
|
+
/** @typedef {(input: string, pos: number, callbacks: CssTokenCallbacks) => number} CharHandler */
|
29
29
|
|
30
30
|
// spec: https://drafts.csswg.org/css-syntax/
|
31
31
|
|