webpack 5.90.3 → 5.91.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/README.md +5 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +262 -93
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +2 -0
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +4 -2
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +118 -24
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +30 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +26 -8
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +3 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +3 -1
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +10 -3
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +117 -64
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +3 -1
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +138 -54
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +7 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- 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 +1668 -613
@@ -8,7 +8,7 @@
|
|
8
8
|
const LazySet = require("../util/LazySet");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
-
/** @typedef {import("enhanced-resolve
|
11
|
+
/** @typedef {import("enhanced-resolve").Resolver} Resolver */
|
12
12
|
/** @typedef {import("../CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
13
13
|
/** @typedef {import("../Compiler")} Compiler */
|
14
14
|
/** @typedef {import("../FileSystemInfo")} FileSystemInfo */
|
@@ -213,7 +213,10 @@ class ResolverCachePlugin {
|
|
213
213
|
stage: -100
|
214
214
|
},
|
215
215
|
(request, resolveContext, callback) => {
|
216
|
-
if (
|
216
|
+
if (
|
217
|
+
/** @type {TODO} */ (request)._ResolverCachePluginCacheMiss ||
|
218
|
+
!fileSystemInfo
|
219
|
+
) {
|
217
220
|
return callback();
|
218
221
|
}
|
219
222
|
const withYield = typeof resolveContext.yield === "function";
|
@@ -225,7 +228,9 @@ class ResolverCachePlugin {
|
|
225
228
|
const activeRequest = activeRequestsWithYield.get(identifier);
|
226
229
|
if (activeRequest) {
|
227
230
|
activeRequest[0].push(callback);
|
228
|
-
activeRequest[1].push(
|
231
|
+
activeRequest[1].push(
|
232
|
+
/** @type {TODO} */ (resolveContext.yield)
|
233
|
+
);
|
229
234
|
return;
|
230
235
|
}
|
231
236
|
} else {
|
@@ -303,19 +308,22 @@ class ResolverCachePlugin {
|
|
303
308
|
cachedResolves++;
|
304
309
|
if (resolveContext.missingDependencies) {
|
305
310
|
addAllToSet(
|
306
|
-
|
311
|
+
/** @type {LazySet<string>} */
|
312
|
+
(resolveContext.missingDependencies),
|
307
313
|
snapshot.getMissingIterable()
|
308
314
|
);
|
309
315
|
}
|
310
316
|
if (resolveContext.fileDependencies) {
|
311
317
|
addAllToSet(
|
312
|
-
|
318
|
+
/** @type {LazySet<string>} */
|
319
|
+
(resolveContext.fileDependencies),
|
313
320
|
snapshot.getFileIterable()
|
314
321
|
);
|
315
322
|
}
|
316
323
|
if (resolveContext.contextDependencies) {
|
317
324
|
addAllToSet(
|
318
|
-
|
325
|
+
/** @type {LazySet<string>} */
|
326
|
+
(resolveContext.contextDependencies),
|
319
327
|
snapshot.getContextIterable()
|
320
328
|
);
|
321
329
|
}
|
@@ -47,7 +47,7 @@ const mapObjects = new WeakMap();
|
|
47
47
|
|
48
48
|
/**
|
49
49
|
* @param {HashableObject} obj object with updateHash method
|
50
|
-
* @param {string | HashConstructor} hashFunction the hash function to use
|
50
|
+
* @param {(string | HashConstructor)=} hashFunction the hash function to use
|
51
51
|
* @returns {LazyHashedEtag} etag
|
52
52
|
*/
|
53
53
|
const getter = (obj, hashFunction = "md4") => {
|
package/lib/config/defaults.js
CHANGED
@@ -472,7 +472,6 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
472
472
|
}
|
473
473
|
return [];
|
474
474
|
});
|
475
|
-
F(snapshot, "unmanagedPaths", () => []);
|
476
475
|
A(snapshot, "immutablePaths", () => {
|
477
476
|
if (process.versions.pnp === "1") {
|
478
477
|
const match =
|
@@ -494,6 +493,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
|
|
494
493
|
return [];
|
495
494
|
});
|
496
495
|
}
|
496
|
+
F(snapshot, "unmanagedPaths", () => []);
|
497
497
|
F(snapshot, "resolveBuildDependencies", () => ({
|
498
498
|
timestamp: true,
|
499
499
|
hash: true
|
@@ -554,6 +554,7 @@ const applyCssGeneratorOptionsDefaults = (
|
|
554
554
|
"exportsOnly",
|
555
555
|
!targetProperties || !targetProperties.document
|
556
556
|
);
|
557
|
+
D(generatorOptions, "exportsConvention", "as-is");
|
557
558
|
};
|
558
559
|
|
559
560
|
/**
|
@@ -641,6 +642,27 @@ const applyModuleDefaults = (
|
|
641
642
|
(module.generator.css),
|
642
643
|
{ targetProperties }
|
643
644
|
);
|
645
|
+
|
646
|
+
F(module.generator, "css/auto", () => ({}));
|
647
|
+
D(
|
648
|
+
module.generator["css/auto"],
|
649
|
+
"localIdentName",
|
650
|
+
"[uniqueName]-[id]-[local]"
|
651
|
+
);
|
652
|
+
|
653
|
+
F(module.generator, "css/module", () => ({}));
|
654
|
+
D(
|
655
|
+
module.generator["css/module"],
|
656
|
+
"localIdentName",
|
657
|
+
"[uniqueName]-[id]-[local]"
|
658
|
+
);
|
659
|
+
|
660
|
+
F(module.generator, "css/global", () => ({}));
|
661
|
+
D(
|
662
|
+
module.generator["css/global"],
|
663
|
+
"localIdentName",
|
664
|
+
"[uniqueName]-[id]-[local]"
|
665
|
+
);
|
644
666
|
}
|
645
667
|
|
646
668
|
A(module, "defaultRules", () => {
|
@@ -901,6 +923,7 @@ const applyOutputDefaults = (
|
|
901
923
|
}
|
902
924
|
return "[id].css";
|
903
925
|
});
|
926
|
+
D(output, "cssHeadDataCompression", !development);
|
904
927
|
D(output, "assetModuleFilename", "[hash][ext][query]");
|
905
928
|
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
906
929
|
D(output, "compareBeforeEmit", true);
|
@@ -320,6 +320,7 @@ const getNormalizedWebpackOptions = config => {
|
|
320
320
|
chunkLoadTimeout: output.chunkLoadTimeout,
|
321
321
|
cssFilename: output.cssFilename,
|
322
322
|
cssChunkFilename: output.cssChunkFilename,
|
323
|
+
cssHeadDataCompression: output.cssHeadDataCompression,
|
323
324
|
clean: output.clean,
|
324
325
|
compareBeforeEmit: output.compareBeforeEmit,
|
325
326
|
crossOriginLoading: output.crossOriginLoading,
|
@@ -446,7 +447,8 @@ const getNormalizedWebpackOptions = config => {
|
|
446
447
|
hash: module.hash
|
447
448
|
})),
|
448
449
|
immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]),
|
449
|
-
managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p])
|
450
|
+
managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]),
|
451
|
+
unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, p => [...p])
|
450
452
|
})),
|
451
453
|
stats: nestedConfig(config.stats, stats => {
|
452
454
|
if (stats === false) {
|
@@ -9,11 +9,12 @@ const Dependency = require("../Dependency");
|
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
11
|
/** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
|
12
|
+
/** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
|
12
13
|
|
13
14
|
class ContainerEntryDependency extends Dependency {
|
14
15
|
/**
|
15
16
|
* @param {string} name entry name
|
16
|
-
* @param {
|
17
|
+
* @param {ExposesList} exposes list of exposed modules
|
17
18
|
* @param {string} shareScope name of the share scope
|
18
19
|
*/
|
19
20
|
constructor(name, exposes, shareScope) {
|
@@ -39,12 +39,14 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
|
|
39
39
|
* @property {string} name custom chunk name for the exposed module
|
40
40
|
*/
|
41
41
|
|
42
|
+
/** @typedef {[string, ExposeOptions][]} ExposesList */
|
43
|
+
|
42
44
|
const SOURCE_TYPES = new Set(["javascript"]);
|
43
45
|
|
44
46
|
class ContainerEntryModule extends Module {
|
45
47
|
/**
|
46
48
|
* @param {string} name container entry name
|
47
|
-
* @param {
|
49
|
+
* @param {ExposesList} exposes list of exposed modules
|
48
50
|
* @param {string} shareScope name of the share scope
|
49
51
|
*/
|
50
52
|
constructor(name, exposes, shareScope) {
|
@@ -13,6 +13,8 @@ const { parseOptions } = require("./options");
|
|
13
13
|
|
14
14
|
/** @typedef {import("../../declarations/plugins/container/ContainerPlugin").ContainerPluginOptions} ContainerPluginOptions */
|
15
15
|
/** @typedef {import("../Compiler")} Compiler */
|
16
|
+
/** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
|
17
|
+
/** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
|
16
18
|
|
17
19
|
const validate = createSchemaValidation(
|
18
20
|
require("../../schemas/plugins/container/ContainerPlugin.check.js"),
|
@@ -41,16 +43,18 @@ class ContainerPlugin {
|
|
41
43
|
},
|
42
44
|
runtime: options.runtime,
|
43
45
|
filename: options.filename || undefined,
|
44
|
-
exposes:
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
exposes: /** @type {ExposesList} */ (
|
47
|
+
parseOptions(
|
48
|
+
options.exposes,
|
49
|
+
item => ({
|
50
|
+
import: Array.isArray(item) ? item : [item],
|
51
|
+
name: undefined
|
52
|
+
}),
|
53
|
+
item => ({
|
54
|
+
import: Array.isArray(item.import) ? item.import : [item.import],
|
55
|
+
name: item.name || undefined
|
56
|
+
})
|
57
|
+
)
|
54
58
|
)
|
55
59
|
};
|
56
60
|
}
|
@@ -129,7 +129,7 @@ class FallbackModule extends Module {
|
|
129
129
|
*/
|
130
130
|
codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
|
131
131
|
const ids = this.dependencies.map(dep =>
|
132
|
-
chunkGraph.getModuleId(moduleGraph.getModule(dep))
|
132
|
+
chunkGraph.getModuleId(/** @type {Module} */ (moduleGraph.getModule(dep)))
|
133
133
|
);
|
134
134
|
const code = Template.asString([
|
135
135
|
`var ids = ${JSON.stringify(ids)};`,
|
@@ -10,6 +10,9 @@ const RuntimeModule = require("../RuntimeModule");
|
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
12
|
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
14
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
15
|
+
/** @typedef {import("../Compilation")} Compilation */
|
13
16
|
/** @typedef {import("./RemoteModule")} RemoteModule */
|
14
17
|
|
15
18
|
class RemoteRuntimeModule extends RuntimeModule {
|
@@ -21,17 +24,23 @@ class RemoteRuntimeModule extends RuntimeModule {
|
|
21
24
|
* @returns {string | null} runtime code
|
22
25
|
*/
|
23
26
|
generate() {
|
24
|
-
const
|
27
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
28
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
25
29
|
const { runtimeTemplate, moduleGraph } = compilation;
|
30
|
+
/** @type {Record<ChunkId, (string | number)[]>} */
|
26
31
|
const chunkToRemotesMapping = {};
|
32
|
+
/** @type {Record<string | number, [string, string, string | number | null]>} */
|
27
33
|
const idToExternalAndNameMapping = {};
|
28
|
-
for (const chunk of this.chunk.getAllAsyncChunks()) {
|
34
|
+
for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
|
29
35
|
const modules = chunkGraph.getChunkModulesIterableBySourceType(
|
30
36
|
chunk,
|
31
37
|
"remote"
|
32
38
|
);
|
33
39
|
if (!modules) continue;
|
34
|
-
|
40
|
+
/** @type {(string | number)[]} */
|
41
|
+
const remotes = (chunkToRemotesMapping[
|
42
|
+
/** @type {ChunkId} */ (chunk.id)
|
43
|
+
] = []);
|
35
44
|
for (const m of modules) {
|
36
45
|
const module = /** @type {RemoteModule} */ (m);
|
37
46
|
const name = module.internalRequest;
|
@@ -10,8 +10,11 @@ const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const Generator = require("../Generator");
|
11
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
12
|
const Template = require("../Template");
|
13
|
+
const { cssExportConvention } = require("../util/conventions");
|
13
14
|
|
14
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
17
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
15
18
|
/** @typedef {import("../Dependency")} Dependency */
|
16
19
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
17
20
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
@@ -27,8 +30,16 @@ const Template = require("../Template");
|
|
27
30
|
const TYPES = new Set(["javascript"]);
|
28
31
|
|
29
32
|
class CssExportsGenerator extends Generator {
|
30
|
-
|
33
|
+
/**
|
34
|
+
* @param {CssGeneratorExportsConvention} convention the convention of the exports name
|
35
|
+
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
|
36
|
+
*/
|
37
|
+
constructor(convention, localIdentName) {
|
31
38
|
super();
|
39
|
+
/** @type {CssGeneratorExportsConvention} */
|
40
|
+
this.convention = convention;
|
41
|
+
/** @type {CssGeneratorLocalIdentName | undefined} */
|
42
|
+
this.localIdentName = localIdentName;
|
32
43
|
}
|
33
44
|
|
34
45
|
// TODO add getConcatenationBailoutReason to allow concatenation
|
@@ -43,6 +54,7 @@ class CssExportsGenerator extends Generator {
|
|
43
54
|
const source = new ReplaceSource(new RawSource(""));
|
44
55
|
/** @type {InitFragment<TODO>[]} */
|
45
56
|
const initFragments = [];
|
57
|
+
/** @type {Map<string, string>} */
|
46
58
|
const cssExports = new Map();
|
47
59
|
|
48
60
|
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
@@ -97,19 +109,21 @@ class CssExportsGenerator extends Generator {
|
|
97
109
|
if (generateContext.concatenationScope) {
|
98
110
|
const source = new ConcatSource();
|
99
111
|
const usedIdentifiers = new Set();
|
100
|
-
for (const [
|
101
|
-
let
|
102
|
-
|
103
|
-
|
104
|
-
|
112
|
+
for (const [name, v] of cssExports) {
|
113
|
+
for (let k of cssExportConvention(name, this.convention)) {
|
114
|
+
let identifier = Template.toIdentifier(k);
|
115
|
+
let i = 0;
|
116
|
+
while (usedIdentifiers.has(identifier)) {
|
117
|
+
identifier = Template.toIdentifier(k + i);
|
118
|
+
}
|
119
|
+
usedIdentifiers.add(identifier);
|
120
|
+
generateContext.concatenationScope.registerExport(k, identifier);
|
121
|
+
source.add(
|
122
|
+
`${
|
123
|
+
generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
|
124
|
+
} ${identifier} = ${JSON.stringify(v)};\n`
|
125
|
+
);
|
105
126
|
}
|
106
|
-
usedIdentifiers.add(identifier);
|
107
|
-
generateContext.concatenationScope.registerExport(k, identifier);
|
108
|
-
source.add(
|
109
|
-
`${
|
110
|
-
generateContext.runtimeTemplate.supportsConst ? "const" : "var"
|
111
|
-
} ${identifier} = ${JSON.stringify(v)};\n`
|
112
|
-
);
|
113
127
|
}
|
114
128
|
return source;
|
115
129
|
} else {
|
@@ -123,13 +137,16 @@ class CssExportsGenerator extends Generator {
|
|
123
137
|
RuntimeGlobals.makeNamespaceObject
|
124
138
|
);
|
125
139
|
}
|
140
|
+
const newCssExports = [];
|
141
|
+
for (let [k, v] of cssExports) {
|
142
|
+
for (let name of cssExportConvention(k, this.convention)) {
|
143
|
+
newCssExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
144
|
+
}
|
145
|
+
}
|
126
146
|
return new RawSource(
|
127
147
|
`${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
128
148
|
module.moduleArgument
|
129
|
-
}.exports = {\n${
|
130
|
-
cssExports,
|
131
|
-
([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
|
132
|
-
).join(",\n")}\n}${otherUsed ? ")" : ""};`
|
149
|
+
}.exports = {\n${newCssExports.join(",\n")}\n}${otherUsed ? ")" : ""};`
|
133
150
|
);
|
134
151
|
}
|
135
152
|
}
|
package/lib/css/CssGenerator.js
CHANGED
@@ -9,8 +9,11 @@ const { ReplaceSource } = require("webpack-sources");
|
|
9
9
|
const Generator = require("../Generator");
|
10
10
|
const InitFragment = require("../InitFragment");
|
11
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
|
+
const { cssExportConvention } = require("../util/conventions");
|
12
13
|
|
13
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
15
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
14
17
|
/** @typedef {import("../Dependency")} Dependency */
|
15
18
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
16
19
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
@@ -20,8 +23,16 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
20
23
|
const TYPES = new Set(["css"]);
|
21
24
|
|
22
25
|
class CssGenerator extends Generator {
|
23
|
-
|
26
|
+
/**
|
27
|
+
* @param {CssGeneratorExportsConvention} convention the convention of the exports name
|
28
|
+
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
|
29
|
+
*/
|
30
|
+
constructor(convention, localIdentName) {
|
24
31
|
super();
|
32
|
+
/** @type {CssGeneratorExportsConvention} */
|
33
|
+
this.convention = convention;
|
34
|
+
/** @type {CssGeneratorLocalIdentName | undefined} */
|
35
|
+
this.localIdentName = localIdentName;
|
25
36
|
}
|
26
37
|
|
27
38
|
/**
|
@@ -34,6 +45,7 @@ class CssGenerator extends Generator {
|
|
34
45
|
const source = new ReplaceSource(originalSource);
|
35
46
|
/** @type {InitFragment[]} */
|
36
47
|
const initFragments = [];
|
48
|
+
/** @type {Map<string, string>} */
|
37
49
|
const cssExports = new Map();
|
38
50
|
|
39
51
|
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
@@ -86,8 +98,14 @@ class CssGenerator extends Generator {
|
|
86
98
|
module.presentationalDependencies.forEach(handleDependency);
|
87
99
|
|
88
100
|
if (cssExports.size > 0) {
|
101
|
+
const newCssExports = new Map();
|
102
|
+
for (let [name, v] of cssExports) {
|
103
|
+
for (let newName of cssExportConvention(name, this.convention)) {
|
104
|
+
newCssExports.set(newName, v);
|
105
|
+
}
|
106
|
+
}
|
89
107
|
const data = generateContext.getData();
|
90
|
-
data.set("css-exports",
|
108
|
+
data.set("css-exports", newCssExports);
|
91
109
|
}
|
92
110
|
|
93
111
|
return InitFragment.addToSource(source, initFragments, generateContext);
|