webpack 5.91.0 → 5.92.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/bin/webpack.js +1 -2
- package/lib/APIPlugin.js +6 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +20 -7
- package/lib/ChunkGroup.js +9 -3
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +33 -27
- package/lib/Compiler.js +28 -8
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ContextModule.js +95 -43
- package/lib/DefinePlugin.js +14 -4
- package/lib/Dependency.js +8 -8
- package/lib/DependencyTemplate.js +10 -5
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExternalModule.js +49 -18
- package/lib/FileSystemInfo.js +68 -41
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +2 -3
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/Module.js +11 -12
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +29 -16
- package/lib/ModuleGraph.js +5 -5
- package/lib/MultiCompiler.js +36 -1
- package/lib/NormalModule.js +10 -12
- package/lib/NormalModuleFactory.js +17 -8
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeTemplate.js +22 -18
- package/lib/Stats.js +1 -1
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +16 -1
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/buildChunkGraph.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/cache/ResolverCachePlugin.js +8 -8
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +85 -34
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +43 -17
- package/lib/css/CssGenerator.js +22 -12
- package/lib/css/CssLoadingRuntimeModule.js +8 -5
- package/lib/css/CssModulesPlugin.js +197 -100
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
- package/lib/dependencies/CssUrlDependency.js +5 -4
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportEagerDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +63 -49
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +37 -16
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/nodeConsole.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -76
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -8
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +6 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +3 -3
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +4 -2
- package/lib/util/conventions.js +1 -1
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +15 -15
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +12 -3
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +30 -2
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +213 -81
package/lib/css/CssGenerator.js
CHANGED
@@ -15,6 +15,8 @@ const { cssExportConvention } = require("../util/conventions");
|
|
15
15
|
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
16
16
|
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
17
17
|
/** @typedef {import("../Dependency")} Dependency */
|
18
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
19
|
+
/** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
|
18
20
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
19
21
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
20
22
|
/** @typedef {import("../NormalModule")} NormalModule */
|
@@ -24,15 +26,18 @@ const TYPES = new Set(["css"]);
|
|
24
26
|
|
25
27
|
class CssGenerator extends Generator {
|
26
28
|
/**
|
27
|
-
* @param {CssGeneratorExportsConvention} convention the convention of the exports name
|
29
|
+
* @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
|
28
30
|
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
|
31
|
+
* @param {boolean} esModule whether to use ES modules syntax
|
29
32
|
*/
|
30
|
-
constructor(convention, localIdentName) {
|
33
|
+
constructor(convention, localIdentName, esModule) {
|
31
34
|
super();
|
32
|
-
/** @type {CssGeneratorExportsConvention} */
|
35
|
+
/** @type {CssGeneratorExportsConvention | undefined} */
|
33
36
|
this.convention = convention;
|
34
37
|
/** @type {CssGeneratorLocalIdentName | undefined} */
|
35
38
|
this.localIdentName = localIdentName;
|
39
|
+
/** @type {boolean} */
|
40
|
+
this.esModule = esModule;
|
36
41
|
}
|
37
42
|
|
38
43
|
/**
|
@@ -45,12 +50,16 @@ class CssGenerator extends Generator {
|
|
45
50
|
const source = new ReplaceSource(originalSource);
|
46
51
|
/** @type {InitFragment[]} */
|
47
52
|
const initFragments = [];
|
48
|
-
/** @type {
|
49
|
-
const
|
53
|
+
/** @type {CssExportsData} */
|
54
|
+
const cssExportsData = {
|
55
|
+
esModule: this.esModule,
|
56
|
+
exports: new Map()
|
57
|
+
};
|
50
58
|
|
51
59
|
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
52
60
|
|
53
61
|
let chunkInitFragments;
|
62
|
+
/** @type {DependencyTemplateContext} */
|
54
63
|
const templateContext = {
|
55
64
|
runtimeTemplate: generateContext.runtimeTemplate,
|
56
65
|
dependencyTemplates: generateContext.dependencyTemplates,
|
@@ -62,7 +71,7 @@ class CssGenerator extends Generator {
|
|
62
71
|
concatenationScope: generateContext.concatenationScope,
|
63
72
|
codeGenerationResults: generateContext.codeGenerationResults,
|
64
73
|
initFragments,
|
65
|
-
|
74
|
+
cssExportsData,
|
66
75
|
get chunkInitFragments() {
|
67
76
|
if (!chunkInitFragments) {
|
68
77
|
const data = generateContext.getData();
|
@@ -97,16 +106,17 @@ class CssGenerator extends Generator {
|
|
97
106
|
if (module.presentationalDependencies !== undefined)
|
98
107
|
module.presentationalDependencies.forEach(handleDependency);
|
99
108
|
|
100
|
-
if (
|
101
|
-
const
|
102
|
-
for (let [name, v] of
|
109
|
+
if (cssExportsData.exports.size > 0) {
|
110
|
+
const newExports = new Map();
|
111
|
+
for (let [name, v] of cssExportsData.exports) {
|
103
112
|
for (let newName of cssExportConvention(name, this.convention)) {
|
104
|
-
|
113
|
+
newExports.set(newName, v);
|
105
114
|
}
|
106
115
|
}
|
107
|
-
|
108
|
-
data.set("css-exports", newCssExports);
|
116
|
+
cssExportsData.exports = newExports;
|
109
117
|
}
|
118
|
+
const data = generateContext.getData();
|
119
|
+
data.set("css-exports", cssExportsData);
|
110
120
|
|
111
121
|
return InitFragment.addToSource(source, initFragments, generateContext);
|
112
122
|
}
|
@@ -19,7 +19,7 @@ const { chunkHasCss } = require("./CssModulesPlugin");
|
|
19
19
|
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
20
20
|
|
21
21
|
/**
|
22
|
-
* @typedef {
|
22
|
+
* @typedef {object} CssLoadingRuntimeModulePluginHooks
|
23
23
|
* @property {SyncWaterfallHook<[string, Chunk]>} createStylesheet
|
24
24
|
* @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
|
25
25
|
* @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
|
@@ -224,7 +224,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
224
224
|
withCompression
|
225
225
|
? Template.asString([
|
226
226
|
// LZW decode
|
227
|
-
`var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = "\uffff".charCodeAt(
|
227
|
+
`var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = ${"\uffff".charCodeAt(
|
228
|
+
0
|
229
|
+
)}, phrase;`,
|
228
230
|
"for (i = 1; i < data.length; i++) {",
|
229
231
|
Template.indent([
|
230
232
|
"cc = data[i].charCodeAt(0);",
|
@@ -246,11 +248,12 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
246
248
|
`else if(cc == ${cc(
|
247
249
|
"/"
|
248
250
|
)}) { token = token.replace(/^_/, ""); token2 = token2.replace(/^_/, ""); exports[token2] = token; token = ""; token2 = ""; }`,
|
251
|
+
`else if(cc == ${cc("&")}) { ${
|
252
|
+
RuntimeGlobals.makeNamespaceObject
|
253
|
+
}(exports); }`,
|
249
254
|
`else if(!cc || cc == ${cc(
|
250
255
|
","
|
251
|
-
)}) { token = token.replace(/^_/, ""); ${
|
252
|
-
RuntimeGlobals.makeNamespaceObject
|
253
|
-
}(exports); target[token] = (${runtimeTemplate.basicFunction(
|
256
|
+
)}) { token = token.replace(/^_/, ""); target[token] = (${runtimeTemplate.basicFunction(
|
254
257
|
"exports, module",
|
255
258
|
`module.exports = exports;`
|
256
259
|
)}).bind(null, exports); ${
|
@@ -5,7 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const {
|
8
|
+
const {
|
9
|
+
ConcatSource,
|
10
|
+
PrefixSource,
|
11
|
+
ReplaceSource,
|
12
|
+
CachedSource
|
13
|
+
} = require("webpack-sources");
|
9
14
|
const CssModule = require("../CssModule");
|
10
15
|
const HotUpdateChunk = require("../HotUpdateChunk");
|
11
16
|
const {
|
@@ -26,6 +31,7 @@ const StaticExportsDependency = require("../dependencies/StaticExportsDependency
|
|
26
31
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
27
32
|
const createSchemaValidation = require("../util/create-schema-validation");
|
28
33
|
const createHash = require("../util/createHash");
|
34
|
+
const { getUndoPath } = require("../util/identifier");
|
29
35
|
const memoize = require("../util/memoize");
|
30
36
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
31
37
|
const CssExportsGenerator = require("./CssExportsGenerator");
|
@@ -39,6 +45,8 @@ const CssParser = require("./CssParser");
|
|
39
45
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
40
46
|
/** @typedef {import("../Compilation")} Compilation */
|
41
47
|
/** @typedef {import("../Compiler")} Compiler */
|
48
|
+
/** @typedef {import("../CssModule").Inheritance} Inheritance */
|
49
|
+
/** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
|
42
50
|
/** @typedef {import("../Module")} Module */
|
43
51
|
/** @typedef {import("../util/memoize")} Memoize */
|
44
52
|
|
@@ -160,6 +168,11 @@ const LZWEncode = str => {
|
|
160
168
|
const plugin = "CssModulesPlugin";
|
161
169
|
|
162
170
|
class CssModulesPlugin {
|
171
|
+
constructor() {
|
172
|
+
/** @type {WeakMap<Source, { undoPath: string, inheritance: Inheritance, source: CachedSource }>} */
|
173
|
+
this._moduleCache = new WeakMap();
|
174
|
+
}
|
175
|
+
|
163
176
|
/**
|
164
177
|
* Apply the plugin
|
165
178
|
* @param {Compiler} compiler the compiler instance
|
@@ -219,12 +232,12 @@ class CssModulesPlugin {
|
|
219
232
|
const { namedExports } = parserOptions;
|
220
233
|
|
221
234
|
switch (type) {
|
222
|
-
case
|
235
|
+
case CSS_MODULE_TYPE_GLOBAL:
|
223
236
|
case CSS_MODULE_TYPE_AUTO:
|
224
237
|
return new CssParser({
|
225
238
|
namedExports
|
226
239
|
});
|
227
|
-
case
|
240
|
+
case CSS_MODULE_TYPE:
|
228
241
|
return new CssParser({
|
229
242
|
allowModeSwitch: false,
|
230
243
|
namedExports
|
@@ -244,11 +257,13 @@ class CssModulesPlugin {
|
|
244
257
|
return generatorOptions.exportsOnly
|
245
258
|
? new CssExportsGenerator(
|
246
259
|
generatorOptions.exportsConvention,
|
247
|
-
generatorOptions.localIdentName
|
260
|
+
generatorOptions.localIdentName,
|
261
|
+
generatorOptions.esModule
|
248
262
|
)
|
249
263
|
: new CssGenerator(
|
250
264
|
generatorOptions.exportsConvention,
|
251
|
-
generatorOptions.localIdentName
|
265
|
+
generatorOptions.localIdentName,
|
266
|
+
generatorOptions.esModule
|
252
267
|
);
|
253
268
|
});
|
254
269
|
normalModuleFactory.hooks.createModuleClass
|
@@ -353,6 +368,23 @@ class CssModulesPlugin {
|
|
353
368
|
|
354
369
|
/** @type {CssModule[] | undefined} */
|
355
370
|
const modules = orderedCssModulesPerChunk.get(chunk);
|
371
|
+
const { path: filename, info } = compilation.getPathWithInfo(
|
372
|
+
CssModulesPlugin.getChunkFilenameTemplate(
|
373
|
+
chunk,
|
374
|
+
compilation.outputOptions
|
375
|
+
),
|
376
|
+
{
|
377
|
+
hash,
|
378
|
+
runtime: chunk.runtime,
|
379
|
+
chunk,
|
380
|
+
contentHashType: "css"
|
381
|
+
}
|
382
|
+
);
|
383
|
+
const undoPath = getUndoPath(
|
384
|
+
filename,
|
385
|
+
compilation.outputOptions.path,
|
386
|
+
false
|
387
|
+
);
|
356
388
|
if (modules !== undefined) {
|
357
389
|
result.push({
|
358
390
|
render: () =>
|
@@ -363,18 +395,11 @@ class CssModulesPlugin {
|
|
363
395
|
uniqueName: compilation.outputOptions.uniqueName,
|
364
396
|
cssHeadDataCompression:
|
365
397
|
compilation.outputOptions.cssHeadDataCompression,
|
398
|
+
undoPath,
|
366
399
|
modules
|
367
400
|
}),
|
368
|
-
|
369
|
-
|
370
|
-
compilation.outputOptions
|
371
|
-
),
|
372
|
-
pathOptions: {
|
373
|
-
hash,
|
374
|
-
runtime: chunk.runtime,
|
375
|
-
chunk,
|
376
|
-
contentHashType: "css"
|
377
|
-
},
|
401
|
+
filename,
|
402
|
+
info,
|
378
403
|
identifier: `css${chunk.id}`,
|
379
404
|
hash: chunk.contentHash.css
|
380
405
|
});
|
@@ -392,7 +417,7 @@ class CssModulesPlugin {
|
|
392
417
|
options && options.chunkLoading !== undefined
|
393
418
|
? options.chunkLoading
|
394
419
|
: globalChunkLoading;
|
395
|
-
return chunkLoading === "jsonp";
|
420
|
+
return chunkLoading === "jsonp" || chunkLoading === "import";
|
396
421
|
};
|
397
422
|
const onceForChunkSet = new WeakSet();
|
398
423
|
/**
|
@@ -505,19 +530,17 @@ class CssModulesPlugin {
|
|
505
530
|
}
|
506
531
|
if (hasFailed) {
|
507
532
|
// There is a not resolve-able conflict with the selectedModule
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
);
|
520
|
-
}
|
533
|
+
// TODO print better warning
|
534
|
+
compilation.warnings.push(
|
535
|
+
new WebpackError(
|
536
|
+
`chunk ${chunk.name || chunk.id}\nConflicting order between ${
|
537
|
+
/** @type {Module} */
|
538
|
+
(hasFailed).readableIdentifier(compilation.requestShortener)
|
539
|
+
} and ${selectedModule.readableIdentifier(
|
540
|
+
compilation.requestShortener
|
541
|
+
)}`
|
542
|
+
)
|
543
|
+
);
|
521
544
|
selectedModule = /** @type {Module} */ (hasFailed);
|
522
545
|
}
|
523
546
|
// Insert the selected module into the final modules list
|
@@ -572,9 +595,143 @@ class CssModulesPlugin {
|
|
572
595
|
}
|
573
596
|
|
574
597
|
/**
|
575
|
-
* @param {
|
598
|
+
* @param {object} options options
|
599
|
+
* @param {string[]} options.metaData meta data
|
600
|
+
* @param {string} options.undoPath undo path for public path auto
|
601
|
+
* @param {Chunk} options.chunk chunk
|
602
|
+
* @param {ChunkGraph} options.chunkGraph chunk graph
|
603
|
+
* @param {CodeGenerationResults} options.codeGenerationResults code generation results
|
604
|
+
* @param {CssModule} options.module css module
|
605
|
+
* @returns {Source} css module source
|
606
|
+
*/
|
607
|
+
renderModule({
|
608
|
+
metaData,
|
609
|
+
undoPath,
|
610
|
+
chunk,
|
611
|
+
chunkGraph,
|
612
|
+
codeGenerationResults,
|
613
|
+
module
|
614
|
+
}) {
|
615
|
+
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
616
|
+
const moduleSourceContent =
|
617
|
+
/** @type {Source} */
|
618
|
+
(
|
619
|
+
codeGenResult.sources.get("css") ||
|
620
|
+
codeGenResult.sources.get("css-import")
|
621
|
+
);
|
622
|
+
|
623
|
+
const cacheEntry = this._moduleCache.get(moduleSourceContent);
|
624
|
+
|
625
|
+
/** @type {Inheritance} */
|
626
|
+
let inheritance = [[module.cssLayer, module.supports, module.media]];
|
627
|
+
if (module.inheritance) {
|
628
|
+
inheritance.push(...module.inheritance);
|
629
|
+
}
|
630
|
+
|
631
|
+
let source;
|
632
|
+
if (
|
633
|
+
cacheEntry &&
|
634
|
+
cacheEntry.undoPath === undoPath &&
|
635
|
+
cacheEntry.inheritance.every(([layer, supports, media], i) => {
|
636
|
+
const item = inheritance[i];
|
637
|
+
if (Array.isArray(item)) {
|
638
|
+
return layer === item[0] && supports === item[1] && media === item[2];
|
639
|
+
}
|
640
|
+
return false;
|
641
|
+
})
|
642
|
+
) {
|
643
|
+
source = cacheEntry.source;
|
644
|
+
} else {
|
645
|
+
const moduleSourceCode = /** @type {string} */ (
|
646
|
+
moduleSourceContent.source()
|
647
|
+
);
|
648
|
+
const publicPathAutoRegex = new RegExp(
|
649
|
+
CssUrlDependency.PUBLIC_PATH_AUTO,
|
650
|
+
"g"
|
651
|
+
);
|
652
|
+
/** @type {Source} */
|
653
|
+
let moduleSource = new ReplaceSource(moduleSourceContent);
|
654
|
+
let match;
|
655
|
+
while ((match = publicPathAutoRegex.exec(moduleSourceCode))) {
|
656
|
+
/** @type {ReplaceSource} */ (moduleSource).replace(
|
657
|
+
match.index,
|
658
|
+
(match.index += match[0].length - 1),
|
659
|
+
undoPath
|
660
|
+
);
|
661
|
+
}
|
662
|
+
|
663
|
+
for (let i = 0; i < inheritance.length; i++) {
|
664
|
+
const layer = inheritance[i][0];
|
665
|
+
const supports = inheritance[i][1];
|
666
|
+
const media = inheritance[i][2];
|
667
|
+
|
668
|
+
if (media) {
|
669
|
+
moduleSource = new ConcatSource(
|
670
|
+
`@media ${media} {\n`,
|
671
|
+
new PrefixSource("\t", moduleSource),
|
672
|
+
"}\n"
|
673
|
+
);
|
674
|
+
}
|
675
|
+
|
676
|
+
if (supports) {
|
677
|
+
moduleSource = new ConcatSource(
|
678
|
+
`@supports (${supports}) {\n`,
|
679
|
+
new PrefixSource("\t", moduleSource),
|
680
|
+
"}\n"
|
681
|
+
);
|
682
|
+
}
|
683
|
+
|
684
|
+
// Layer can be anonymous
|
685
|
+
if (layer !== undefined && layer !== null) {
|
686
|
+
moduleSource = new ConcatSource(
|
687
|
+
`@layer${layer ? ` ${layer}` : ""} {\n`,
|
688
|
+
new PrefixSource("\t", moduleSource),
|
689
|
+
"}\n"
|
690
|
+
);
|
691
|
+
}
|
692
|
+
}
|
693
|
+
|
694
|
+
if (moduleSource) {
|
695
|
+
moduleSource = new ConcatSource(moduleSource, "\n");
|
696
|
+
}
|
697
|
+
|
698
|
+
source = new CachedSource(moduleSource);
|
699
|
+
this._moduleCache.set(moduleSourceContent, {
|
700
|
+
inheritance,
|
701
|
+
undoPath,
|
702
|
+
source
|
703
|
+
});
|
704
|
+
}
|
705
|
+
/** @type {CssExportsData | undefined} */
|
706
|
+
const cssExportsData =
|
707
|
+
codeGenResult.data && codeGenResult.data.get("css-exports");
|
708
|
+
const exports = cssExportsData && cssExportsData.exports;
|
709
|
+
const esModule = cssExportsData && cssExportsData.esModule;
|
710
|
+
let moduleId = chunkGraph.getModuleId(module) + "";
|
711
|
+
|
712
|
+
// When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
|
713
|
+
if (typeof moduleId === "string") {
|
714
|
+
moduleId = moduleId.replace(/\\/g, "/");
|
715
|
+
}
|
716
|
+
|
717
|
+
metaData.push(
|
718
|
+
`${
|
719
|
+
exports
|
720
|
+
? Array.from(
|
721
|
+
exports,
|
722
|
+
([n, v]) => `${escapeCss(n)}:${escapeCss(v)}/`
|
723
|
+
).join("")
|
724
|
+
: ""
|
725
|
+
}${esModule ? "&" : ""}${escapeCss(moduleId)}`
|
726
|
+
);
|
727
|
+
return source;
|
728
|
+
}
|
729
|
+
|
730
|
+
/**
|
731
|
+
* @param {object} options options
|
576
732
|
* @param {string | undefined} options.uniqueName unique name
|
577
733
|
* @param {boolean | undefined} options.cssHeadDataCompression compress css head data
|
734
|
+
* @param {string} options.undoPath undo path for public path auto
|
578
735
|
* @param {Chunk} options.chunk chunk
|
579
736
|
* @param {ChunkGraph} options.chunkGraph chunk graph
|
580
737
|
* @param {CodeGenerationResults} options.codeGenerationResults code generation results
|
@@ -584,6 +741,7 @@ class CssModulesPlugin {
|
|
584
741
|
renderChunk({
|
585
742
|
uniqueName,
|
586
743
|
cssHeadDataCompression,
|
744
|
+
undoPath,
|
587
745
|
chunk,
|
588
746
|
chunkGraph,
|
589
747
|
codeGenerationResults,
|
@@ -594,76 +752,15 @@ class CssModulesPlugin {
|
|
594
752
|
const metaData = [];
|
595
753
|
for (const module of modules) {
|
596
754
|
try {
|
597
|
-
const
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
let inheritance = [[module.cssLayer, module.supports, module.media]];
|
607
|
-
|
608
|
-
if (module.inheritance) {
|
609
|
-
inheritance.push(...module.inheritance);
|
610
|
-
}
|
611
|
-
|
612
|
-
for (let i = 0; i < inheritance.length; i++) {
|
613
|
-
const layer = inheritance[i][0];
|
614
|
-
const supports = inheritance[i][1];
|
615
|
-
const media = inheritance[i][2];
|
616
|
-
|
617
|
-
if (media) {
|
618
|
-
moduleSource = new ConcatSource(
|
619
|
-
`@media ${media} {\n`,
|
620
|
-
new PrefixSource("\t", moduleSource),
|
621
|
-
"}\n"
|
622
|
-
);
|
623
|
-
}
|
624
|
-
|
625
|
-
if (supports) {
|
626
|
-
moduleSource = new ConcatSource(
|
627
|
-
`@supports (${supports}) {\n`,
|
628
|
-
new PrefixSource("\t", moduleSource),
|
629
|
-
"}\n"
|
630
|
-
);
|
631
|
-
}
|
632
|
-
|
633
|
-
// Layer can be anonymous
|
634
|
-
if (layer !== undefined && layer !== null) {
|
635
|
-
moduleSource = new ConcatSource(
|
636
|
-
`@layer${layer ? ` ${layer}` : ""} {\n`,
|
637
|
-
new PrefixSource("\t", moduleSource),
|
638
|
-
"}\n"
|
639
|
-
);
|
640
|
-
}
|
641
|
-
}
|
642
|
-
|
643
|
-
if (moduleSource) {
|
644
|
-
source.add(moduleSource);
|
645
|
-
source.add("\n");
|
646
|
-
}
|
647
|
-
/** @type {Map<string, string> | undefined} */
|
648
|
-
const exports =
|
649
|
-
codeGenResult.data && codeGenResult.data.get("css-exports");
|
650
|
-
let moduleId = chunkGraph.getModuleId(module) + "";
|
651
|
-
|
652
|
-
// When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
|
653
|
-
if (typeof moduleId === "string") {
|
654
|
-
moduleId = moduleId.replace(/\\/g, "/");
|
655
|
-
}
|
656
|
-
|
657
|
-
metaData.push(
|
658
|
-
`${
|
659
|
-
exports
|
660
|
-
? Array.from(
|
661
|
-
exports,
|
662
|
-
([n, v]) => `${escapeCss(n)}:${escapeCss(v)}/`
|
663
|
-
).join("")
|
664
|
-
: ""
|
665
|
-
}${escapeCss(moduleId)}`
|
666
|
-
);
|
755
|
+
const moduleSource = this.renderModule({
|
756
|
+
metaData,
|
757
|
+
undoPath,
|
758
|
+
chunk,
|
759
|
+
chunkGraph,
|
760
|
+
codeGenerationResults,
|
761
|
+
module
|
762
|
+
});
|
763
|
+
source.add(moduleSource);
|
667
764
|
} catch (e) {
|
668
765
|
/** @type {Error} */
|
669
766
|
(e).message += `\nduring rendering of css ${module.identifier()}`;
|
package/lib/css/CssParser.js
CHANGED
@@ -600,11 +600,13 @@ class CssParser extends Parser {
|
|
600
600
|
|
601
601
|
return newPos;
|
602
602
|
}
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
603
|
+
if (isLocalMode()) {
|
604
|
+
const { line: sl, column: sc } = locConverter.get(pos);
|
605
|
+
const { line: el, column: ec } = locConverter.get(newPos);
|
606
|
+
const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
|
607
|
+
dep.setLoc(sl, sc, el, ec);
|
608
|
+
module.addDependency(dep);
|
609
|
+
}
|
608
610
|
pos = newPos;
|
609
611
|
return pos + 1;
|
610
612
|
} else if (this.allowModeSwitch && name === "@property") {
|
@@ -630,17 +632,19 @@ class CssParser extends Parser {
|
|
630
632
|
|
631
633
|
return propertyNameEnd;
|
632
634
|
}
|
633
|
-
const { line: sl, column: sc } = locConverter.get(pos);
|
634
|
-
const { line: el, column: ec } = locConverter.get(propertyNameEnd);
|
635
635
|
const name = propertyName.slice(2);
|
636
|
-
const dep = new CssLocalIdentifierDependency(
|
637
|
-
name,
|
638
|
-
[propertyNameStart, propertyNameEnd],
|
639
|
-
"--"
|
640
|
-
);
|
641
|
-
dep.setLoc(sl, sc, el, ec);
|
642
|
-
module.addDependency(dep);
|
643
636
|
declaredCssVariables.add(name);
|
637
|
+
if (isLocalMode()) {
|
638
|
+
const { line: sl, column: sc } = locConverter.get(pos);
|
639
|
+
const { line: el, column: ec } = locConverter.get(propertyNameEnd);
|
640
|
+
const dep = new CssLocalIdentifierDependency(
|
641
|
+
name,
|
642
|
+
[propertyNameStart, propertyNameEnd],
|
643
|
+
"--"
|
644
|
+
);
|
645
|
+
dep.setLoc(sl, sc, el, ec);
|
646
|
+
module.addDependency(dep);
|
647
|
+
}
|
644
648
|
pos = propertyNameEnd;
|
645
649
|
return pos + 1;
|
646
650
|
} else if (
|
@@ -710,7 +714,7 @@ class CssParser extends Parser {
|
|
710
714
|
}
|
711
715
|
|
712
716
|
const semicolonPos = end;
|
713
|
-
end = walkCssTokens.eatWhiteLine(input, end
|
717
|
+
end = walkCssTokens.eatWhiteLine(input, end);
|
714
718
|
const { line: sl, column: sc } = locConverter.get(start);
|
715
719
|
const { line: el, column: ec } = locConverter.get(end);
|
716
720
|
const lastEnd =
|
@@ -1030,6 +1034,11 @@ class CssParser extends Parser {
|
|
1030
1034
|
|
1031
1035
|
module.buildInfo.strict = true;
|
1032
1036
|
module.buildMeta.exportsType = this.namedExports ? "namespace" : "default";
|
1037
|
+
|
1038
|
+
if (!this.namedExports) {
|
1039
|
+
module.buildMeta.defaultObject = "redirect";
|
1040
|
+
}
|
1041
|
+
|
1033
1042
|
module.addDependency(new StaticExportsDependency([], true));
|
1034
1043
|
return state;
|
1035
1044
|
}
|
package/lib/css/walkCssTokens.js
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @typedef {
|
9
|
+
* @typedef {object} CssTokenCallbacks
|
10
10
|
* @property {function(string, number): boolean=} isSelector
|
11
11
|
* @property {function(string, number, number, number, number): number=} url
|
12
12
|
* @property {function(string, number, number): number=} string
|
@@ -137,7 +137,7 @@ class Profiler {
|
|
137
137
|
|
138
138
|
/**
|
139
139
|
* an object that wraps Tracer and Profiler with a counter
|
140
|
-
* @typedef {
|
140
|
+
* @typedef {object} Trace
|
141
141
|
* @property {Tracer} trace instance of Tracer
|
142
142
|
* @property {number} counter Counter
|
143
143
|
* @property {Profiler} profiler instance of Profiler
|
@@ -11,7 +11,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
11
11
|
|
12
12
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
13
13
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
14
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
14
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
15
15
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
16
16
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
17
17
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
@@ -24,7 +24,7 @@ class ContextElementDependency extends ModuleDependency {
|
|
24
24
|
* @param {string} category category
|
25
25
|
* @param {string[][]=} referencedExports referenced exports
|
26
26
|
* @param {string=} context context
|
27
|
-
* @param {
|
27
|
+
* @param {ImportAttributes=} attributes import assertions
|
28
28
|
*/
|
29
29
|
constructor(
|
30
30
|
request,
|
@@ -79,9 +79,9 @@ CssExportDependency.Template = class CssExportDependencyTemplate extends (
|
|
79
79
|
* @param {DependencyTemplateContext} templateContext the context object
|
80
80
|
* @returns {void}
|
81
81
|
*/
|
82
|
-
apply(dependency, source, {
|
82
|
+
apply(dependency, source, { cssExportsData }) {
|
83
83
|
const dep = /** @type {CssExportDependency} */ (dependency);
|
84
|
-
|
84
|
+
cssExportsData.exports.set(dep.name, dep.value);
|
85
85
|
}
|
86
86
|
};
|
87
87
|
|
@@ -157,7 +157,14 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
|
|
157
157
|
apply(
|
158
158
|
dependency,
|
159
159
|
source,
|
160
|
-
{
|
160
|
+
{
|
161
|
+
module,
|
162
|
+
moduleGraph,
|
163
|
+
chunkGraph,
|
164
|
+
runtime,
|
165
|
+
runtimeTemplate,
|
166
|
+
cssExportsData
|
167
|
+
}
|
161
168
|
) {
|
162
169
|
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
163
170
|
const used = moduleGraph
|
@@ -179,7 +186,7 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
|
|
179
186
|
dep.range[1] - 1,
|
180
187
|
escapeCssIdentifier(localIdent, dep.prefix)
|
181
188
|
);
|
182
|
-
if (used)
|
189
|
+
if (used) cssExportsData.exports.set(used, localIdent);
|
183
190
|
}
|
184
191
|
};
|
185
192
|
|