webpack 5.102.0 → 5.103.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.
- package/README.md +121 -134
- package/lib/ChunkGraph.js +2 -2
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +30 -13
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +3 -1
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +12 -12
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DotenvPlugin.js +457 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +20 -28
- package/lib/ExternalModuleFactoryPlugin.js +10 -8
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +9 -12
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +0 -6
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +419 -121
- package/lib/NormalModule.js +18 -17
- package/lib/NormalModuleFactory.js +75 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +125 -57
- package/lib/SourceMapDevToolPlugin.js +26 -8
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +2 -1
- package/lib/asset/AssetGenerator.js +3 -5
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +82 -76
- package/lib/config/defaults.js +105 -20
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +7 -1
- package/lib/css/CssGenerator.js +283 -57
- package/lib/css/CssLoadingRuntimeModule.js +2 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +86 -40
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +98 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssIcssExportDependency.js +247 -8
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
- package/lib/dependencies/CssIcssImportDependency.js +60 -54
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
- package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
- package/lib/dependencies/CssImportDependency.js +15 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
- package/lib/dependencies/HarmonyImportDependency.js +27 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +10 -4
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +98 -10
- package/lib/dependencies/ImportParserPlugin.js +19 -21
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +1 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +5 -2
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +101 -101
- package/lib/javascript/JavascriptModulesPlugin.js +25 -16
- package/lib/javascript/JavascriptParser.js +143 -39
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +19 -5
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +161 -135
- package/lib/optimize/RealContentHashPlugin.js +5 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/serialization/FileMiddleware.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
- package/lib/util/Hash.js +35 -5
- package/lib/util/comparators.js +4 -3
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +85 -15
- package/lib/util/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- package/lib/util/internalSerializables.js +4 -4
- package/lib/util/jsonParseEvenBetterErrors.js +10 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
- package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/wasm-sync/WebAssemblyParser.js +0 -9
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +28 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +110 -15
- package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +788 -127
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
|
@@ -16,6 +16,7 @@ const { cachedSetProperty, resolveByProperty } = require("./util/cleverMerge");
|
|
|
16
16
|
|
|
17
17
|
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
|
|
18
18
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
|
19
|
+
/** @typedef {import("../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
|
19
20
|
/** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
|
|
20
21
|
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
|
|
21
22
|
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
|
|
@@ -50,7 +51,7 @@ const callDeprecatedExternals = util.deprecate(
|
|
|
50
51
|
* @param {EXPECTED_FUNCTION} externalsFunction externals function
|
|
51
52
|
* @param {string} context context
|
|
52
53
|
* @param {string} request request
|
|
53
|
-
* @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty:
|
|
54
|
+
* @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty: ExternalsType | undefined) => void} cb cb
|
|
54
55
|
*/
|
|
55
56
|
(externalsFunction, context, request, cb) => {
|
|
56
57
|
// eslint-disable-next-line no-useless-call
|
|
@@ -90,13 +91,12 @@ const resolveLayer = (obj, layer) => {
|
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
/** @typedef {string | string[] | boolean | Record<string, string | string[]>} ExternalValue */
|
|
93
|
-
/** @typedef {string | undefined} ExternalType */
|
|
94
94
|
|
|
95
95
|
const PLUGIN_NAME = "ExternalModuleFactoryPlugin";
|
|
96
96
|
|
|
97
97
|
class ExternalModuleFactoryPlugin {
|
|
98
98
|
/**
|
|
99
|
-
* @param {
|
|
99
|
+
* @param {ExternalsType} type default external type
|
|
100
100
|
* @param {Externals} externals externals config
|
|
101
101
|
*/
|
|
102
102
|
constructor(type, externals) {
|
|
@@ -122,7 +122,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* @param {ExternalValue} value the external config
|
|
125
|
-
* @param {
|
|
125
|
+
* @param {ExternalsType | undefined} type type of external
|
|
126
126
|
* @param {HandleExternalCallback} callback callback
|
|
127
127
|
* @returns {void}
|
|
128
128
|
*/
|
|
@@ -131,7 +131,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
131
131
|
// Not externals, fallback to original factory
|
|
132
132
|
return callback();
|
|
133
133
|
}
|
|
134
|
-
/** @type {
|
|
134
|
+
/** @type {ExternalValue} */
|
|
135
135
|
let externalConfig = value === true ? dependency.request : value;
|
|
136
136
|
// When no explicit type is specified, extract it from the externalConfig
|
|
137
137
|
if (type === undefined) {
|
|
@@ -140,7 +140,9 @@ class ExternalModuleFactoryPlugin {
|
|
|
140
140
|
UNSPECIFIED_EXTERNAL_TYPE_REGEXP.test(externalConfig)
|
|
141
141
|
) {
|
|
142
142
|
const idx = externalConfig.indexOf(" ");
|
|
143
|
-
type =
|
|
143
|
+
type =
|
|
144
|
+
/** @type {ExternalsType} */
|
|
145
|
+
(externalConfig.slice(0, idx));
|
|
144
146
|
externalConfig = externalConfig.slice(idx + 1);
|
|
145
147
|
} else if (
|
|
146
148
|
Array.isArray(externalConfig) &&
|
|
@@ -149,7 +151,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
149
151
|
) {
|
|
150
152
|
const firstItem = externalConfig[0];
|
|
151
153
|
const idx = firstItem.indexOf(" ");
|
|
152
|
-
type = firstItem.slice(0, idx);
|
|
154
|
+
type = /** @type {ExternalsType} */ (firstItem.slice(0, idx));
|
|
153
155
|
externalConfig = [
|
|
154
156
|
firstItem.slice(idx + 1),
|
|
155
157
|
...externalConfig.slice(1)
|
|
@@ -255,7 +257,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
255
257
|
/**
|
|
256
258
|
* @param {Error | null | undefined} err err
|
|
257
259
|
* @param {ExternalValue=} value value
|
|
258
|
-
* @param {
|
|
260
|
+
* @param {ExternalsType=} type type
|
|
259
261
|
* @returns {void}
|
|
260
262
|
*/
|
|
261
263
|
const cb = (err, value, type) => {
|
package/lib/ExternalsPlugin.js
CHANGED
|
@@ -9,6 +9,7 @@ const { ModuleExternalInitFragment } = require("./ExternalModule");
|
|
|
9
9
|
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
|
10
10
|
const ConcatenatedModule = require("./optimize/ConcatenatedModule");
|
|
11
11
|
|
|
12
|
+
/** @typedef {import("../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
|
12
13
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
|
13
14
|
/** @typedef {import("./Compiler")} Compiler */
|
|
14
15
|
/** @typedef {import("./ExternalModule").Imported} Imported */
|
|
@@ -17,7 +18,7 @@ const PLUGIN_NAME = "ExternalsPlugin";
|
|
|
17
18
|
|
|
18
19
|
class ExternalsPlugin {
|
|
19
20
|
/**
|
|
20
|
-
* @param {
|
|
21
|
+
* @param {ExternalsType} type default external type
|
|
21
22
|
* @param {Externals} externals externals config
|
|
22
23
|
*/
|
|
23
24
|
constructor(type, externals) {
|
package/lib/FileSystemInfo.js
CHANGED
|
@@ -3350,7 +3350,7 @@ class FileSystemInfo {
|
|
|
3350
3350
|
|
|
3351
3351
|
hash.update(/** @type {string | Buffer} */ (content));
|
|
3352
3352
|
|
|
3353
|
-
const digest =
|
|
3353
|
+
const digest = hash.digest("hex");
|
|
3354
3354
|
|
|
3355
3355
|
this._fileHashes.set(path, digest);
|
|
3356
3356
|
|
|
@@ -3618,7 +3618,7 @@ class FileSystemInfo {
|
|
|
3618
3618
|
}
|
|
3619
3619
|
}
|
|
3620
3620
|
|
|
3621
|
-
const digest =
|
|
3621
|
+
const digest = hash.digest("hex");
|
|
3622
3622
|
/** @type {ContextFileSystemInfoEntry} */
|
|
3623
3623
|
const result = {
|
|
3624
3624
|
safeTime,
|
|
@@ -3681,7 +3681,7 @@ class FileSystemInfo {
|
|
|
3681
3681
|
null,
|
|
3682
3682
|
(entry.resolved = {
|
|
3683
3683
|
safeTime,
|
|
3684
|
-
timestampHash:
|
|
3684
|
+
timestampHash: hash.digest("hex")
|
|
3685
3685
|
})
|
|
3686
3686
|
);
|
|
3687
3687
|
}
|
|
@@ -3743,7 +3743,7 @@ class FileSystemInfo {
|
|
|
3743
3743
|
|
|
3744
3744
|
/** @type {ContextHash} */
|
|
3745
3745
|
const result = {
|
|
3746
|
-
hash:
|
|
3746
|
+
hash: hash.digest("hex")
|
|
3747
3747
|
};
|
|
3748
3748
|
if (symlinks) result.symlinks = symlinks;
|
|
3749
3749
|
return result;
|
|
@@ -3790,10 +3790,7 @@ class FileSystemInfo {
|
|
|
3790
3790
|
for (const h of hashes) {
|
|
3791
3791
|
hash.update(h);
|
|
3792
3792
|
}
|
|
3793
|
-
callback(
|
|
3794
|
-
null,
|
|
3795
|
-
(entry.resolved = /** @type {string} */ (hash.digest("hex")))
|
|
3796
|
-
);
|
|
3793
|
+
callback(null, (entry.resolved = hash.digest("hex")));
|
|
3797
3794
|
}
|
|
3798
3795
|
);
|
|
3799
3796
|
}
|
|
@@ -3910,8 +3907,8 @@ class FileSystemInfo {
|
|
|
3910
3907
|
/** @type {ContextTimestampAndHash} */
|
|
3911
3908
|
const result = {
|
|
3912
3909
|
safeTime,
|
|
3913
|
-
timestampHash:
|
|
3914
|
-
hash:
|
|
3910
|
+
timestampHash: tsHash.digest("hex"),
|
|
3911
|
+
hash: hash.digest("hex")
|
|
3915
3912
|
};
|
|
3916
3913
|
if (symlinks) result.symlinks = symlinks;
|
|
3917
3914
|
return result;
|
|
@@ -3979,8 +3976,8 @@ class FileSystemInfo {
|
|
|
3979
3976
|
null,
|
|
3980
3977
|
(entry.resolved = {
|
|
3981
3978
|
safeTime,
|
|
3982
|
-
timestampHash:
|
|
3983
|
-
hash:
|
|
3979
|
+
timestampHash: tsHash.digest("hex"),
|
|
3980
|
+
hash: hash.digest("hex")
|
|
3984
3981
|
})
|
|
3985
3982
|
);
|
|
3986
3983
|
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Haijie Xie @hai-x
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { RawSource } = require("webpack-sources");
|
|
9
|
+
const Compilation = require("./Compilation");
|
|
10
|
+
const HotUpdateChunk = require("./HotUpdateChunk");
|
|
11
|
+
const createSchemaValidation = require("./util/create-schema-validation");
|
|
12
|
+
|
|
13
|
+
/** @typedef {import("./Compiler")} Compiler */
|
|
14
|
+
/** @typedef {import("./Chunk")} Chunk */
|
|
15
|
+
/** @typedef {import("./Chunk").ChunkName} ChunkName */
|
|
16
|
+
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
|
17
|
+
/** @typedef {import("./Compilation").Asset} Asset */
|
|
18
|
+
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
|
19
|
+
|
|
20
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestPluginOptions} ManifestPluginOptions */
|
|
21
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestObject} ManifestObject */
|
|
22
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestEntrypoint} ManifestEntrypoint */
|
|
23
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestItem} ManifestItem */
|
|
24
|
+
|
|
25
|
+
const PLUGIN_NAME = "ManifestPlugin";
|
|
26
|
+
|
|
27
|
+
const validate = createSchemaValidation(
|
|
28
|
+
require("../schemas/plugins/ManifestPlugin.check"),
|
|
29
|
+
() => require("../schemas/plugins/ManifestPlugin.json"),
|
|
30
|
+
{
|
|
31
|
+
name: "ManifestPlugin",
|
|
32
|
+
baseDataPath: "options"
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} filename filename
|
|
38
|
+
* @returns {string} extname
|
|
39
|
+
*/
|
|
40
|
+
const extname = (filename) => {
|
|
41
|
+
const replaced = filename.replace(/\?.*/, "");
|
|
42
|
+
const split = replaced.split(".");
|
|
43
|
+
const last = split.pop();
|
|
44
|
+
if (!last) return "";
|
|
45
|
+
return last && /^(gz|br|map)$/i.test(last) ? `${split.pop()}.${last}` : last;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
class ManifestPlugin {
|
|
49
|
+
/**
|
|
50
|
+
* @param {ManifestPluginOptions} options options
|
|
51
|
+
*/
|
|
52
|
+
constructor(options) {
|
|
53
|
+
validate(options);
|
|
54
|
+
|
|
55
|
+
/** @type {ManifestPluginOptions & Required<Omit<ManifestPluginOptions, "filter" | "generate">>} */
|
|
56
|
+
this.options = {
|
|
57
|
+
filename: "manifest.json",
|
|
58
|
+
prefix: "[publicpath]",
|
|
59
|
+
entrypoints: true,
|
|
60
|
+
serialize: (manifest) => JSON.stringify(manifest, null, 2),
|
|
61
|
+
...options
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Apply the plugin
|
|
67
|
+
* @param {Compiler} compiler the compiler instance
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
70
|
+
apply(compiler) {
|
|
71
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
72
|
+
compilation.hooks.processAssets.tap(
|
|
73
|
+
{
|
|
74
|
+
name: PLUGIN_NAME,
|
|
75
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
76
|
+
},
|
|
77
|
+
() => {
|
|
78
|
+
const hashDigestLength = compilation.outputOptions.hashDigestLength;
|
|
79
|
+
const publicPath = compilation.getPath(
|
|
80
|
+
compilation.outputOptions.publicPath
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {string | string[]} value value
|
|
85
|
+
* @returns {RegExp} regexp to remove hash
|
|
86
|
+
*/
|
|
87
|
+
const createHashRegExp = (value) =>
|
|
88
|
+
new RegExp(
|
|
89
|
+
`(?:\\.${Array.isArray(value) ? `(${value.join("|")})` : value})(?=\\.)`,
|
|
90
|
+
"gi"
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} name name
|
|
95
|
+
* @param {AssetInfo | null} info asset info
|
|
96
|
+
* @returns {string} hash removed name
|
|
97
|
+
*/
|
|
98
|
+
const removeHash = (name, info) => {
|
|
99
|
+
// Handles hashes that match configured `hashDigestLength`
|
|
100
|
+
// i.e. index.XXXX.html -> index.html (html-webpack-plugin)
|
|
101
|
+
if (hashDigestLength <= 0) return name;
|
|
102
|
+
const reg = createHashRegExp(`[a-f0-9]{${hashDigestLength},32}`);
|
|
103
|
+
return name.replace(reg, "");
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {Chunk} chunk chunk
|
|
108
|
+
* @returns {ChunkName | ChunkId} chunk name or chunk id
|
|
109
|
+
*/
|
|
110
|
+
const getName = (chunk) => {
|
|
111
|
+
if (chunk.name) return chunk.name;
|
|
112
|
+
|
|
113
|
+
return chunk.id;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** @type {ManifestObject} */
|
|
117
|
+
let manifest = {};
|
|
118
|
+
|
|
119
|
+
if (this.options.entrypoints) {
|
|
120
|
+
/** @type {ManifestObject["entrypoints"]} */
|
|
121
|
+
const entrypoints = {};
|
|
122
|
+
|
|
123
|
+
for (const [name, entrypoint] of compilation.entrypoints) {
|
|
124
|
+
const imports = [];
|
|
125
|
+
|
|
126
|
+
for (const chunk of entrypoint.chunks) {
|
|
127
|
+
for (const file of chunk.files) {
|
|
128
|
+
const name = getName(chunk);
|
|
129
|
+
|
|
130
|
+
imports.push(name ? `${name}.${extname(file)}` : file);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @type {ManifestEntrypoint} */
|
|
135
|
+
const item = { imports };
|
|
136
|
+
const parents = entrypoint
|
|
137
|
+
.getParents()
|
|
138
|
+
.map((item) => /** @type {string} */ (item.name));
|
|
139
|
+
|
|
140
|
+
if (parents.length > 0) {
|
|
141
|
+
item.parents = parents;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
entrypoints[name] = item;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
manifest.entrypoints = entrypoints;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @type {ManifestObject["assets"]} */
|
|
151
|
+
const assets = {};
|
|
152
|
+
|
|
153
|
+
/** @type {Set<string>} */
|
|
154
|
+
const added = new Set();
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {string} file file
|
|
158
|
+
* @param {string=} usedName usedName
|
|
159
|
+
* @returns {void}
|
|
160
|
+
*/
|
|
161
|
+
const handleFile = (file, usedName) => {
|
|
162
|
+
if (added.has(file)) return;
|
|
163
|
+
added.add(file);
|
|
164
|
+
|
|
165
|
+
const asset = compilation.getAsset(file);
|
|
166
|
+
if (!asset) return;
|
|
167
|
+
const sourceFilename = asset.info.sourceFilename;
|
|
168
|
+
const name =
|
|
169
|
+
usedName ||
|
|
170
|
+
sourceFilename ||
|
|
171
|
+
// Fallback for unofficial plugins, just remove hash from filename
|
|
172
|
+
removeHash(file, asset.info);
|
|
173
|
+
|
|
174
|
+
const prefix = this.options.prefix.replace(
|
|
175
|
+
/\[publicpath\]/gi,
|
|
176
|
+
() => (publicPath === "auto" ? "/" : publicPath)
|
|
177
|
+
);
|
|
178
|
+
/** @type {ManifestItem} */
|
|
179
|
+
const item = { file: prefix + file };
|
|
180
|
+
|
|
181
|
+
if (sourceFilename) {
|
|
182
|
+
item.src = sourceFilename;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (this.options.filter) {
|
|
186
|
+
const needKeep = this.options.filter(item);
|
|
187
|
+
|
|
188
|
+
if (!needKeep) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
assets[name] = item;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
for (const chunk of compilation.chunks) {
|
|
197
|
+
if (chunk instanceof HotUpdateChunk) continue;
|
|
198
|
+
|
|
199
|
+
for (const auxiliaryFile of chunk.auxiliaryFiles) {
|
|
200
|
+
handleFile(auxiliaryFile);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const name = getName(chunk);
|
|
204
|
+
|
|
205
|
+
for (const file of chunk.files) {
|
|
206
|
+
handleFile(file, name ? `${name}.${extname(file)}` : file);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
for (const asset of compilation.getAssets()) {
|
|
211
|
+
if (asset.info.hotModuleReplacement) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
handleFile(asset.name);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
manifest.assets = assets;
|
|
219
|
+
|
|
220
|
+
if (this.options.generate) {
|
|
221
|
+
manifest = this.options.generate(manifest);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
compilation.emitAsset(
|
|
225
|
+
this.options.filename,
|
|
226
|
+
new RawSource(this.options.serialize(manifest)),
|
|
227
|
+
{ manifest: true }
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports = ManifestPlugin;
|
package/lib/Module.js
CHANGED
|
@@ -39,6 +39,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
39
39
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
40
40
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
41
41
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|
42
|
+
/** @typedef {import("../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
|
|
43
|
+
|
|
42
44
|
/**
|
|
43
45
|
* @template T
|
|
44
46
|
* @typedef {import("./InitFragment")<T>} InitFragment
|
|
@@ -116,6 +118,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
116
118
|
/**
|
|
117
119
|
* @typedef {object} KnownBuildMeta
|
|
118
120
|
* @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
|
|
121
|
+
* @property {CssParserExportType=} exportType
|
|
119
122
|
* @property {(false | "redirect" | "redirect-warn")=} defaultObject
|
|
120
123
|
* @property {boolean=} strictHarmonyModule
|
|
121
124
|
* @property {boolean=} treatAsCommonJs
|
package/lib/ModuleGraph.js
CHANGED
|
@@ -9,6 +9,7 @@ const util = require("util");
|
|
|
9
9
|
const ExportsInfo = require("./ExportsInfo");
|
|
10
10
|
const ModuleGraphConnection = require("./ModuleGraphConnection");
|
|
11
11
|
const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
|
|
12
|
+
const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
12
13
|
const SortableSet = require("./util/SortableSet");
|
|
13
14
|
const WeakTupleMap = require("./util/WeakTupleMap");
|
|
14
15
|
const { sortWithSourceOrder } = require("./util/comparators");
|
|
@@ -844,7 +845,7 @@ class ModuleGraph {
|
|
|
844
845
|
) {
|
|
845
846
|
continue;
|
|
846
847
|
}
|
|
847
|
-
if (connection.dependency.
|
|
848
|
+
if (ImportPhaseUtils.isDefer(connection.dependency.phase)) return true;
|
|
848
849
|
}
|
|
849
850
|
return false;
|
|
850
851
|
}
|
|
@@ -44,11 +44,6 @@ const JS_TYPE = "javascript";
|
|
|
44
44
|
*/
|
|
45
45
|
const JS_TYPES = new Set(["javascript"]);
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* @type {ReadonlySet<"javascript" | "css-export">}
|
|
49
|
-
*/
|
|
50
|
-
const JS_AND_CSS_EXPORT_TYPES = new Set(["javascript", "css-export"]);
|
|
51
|
-
|
|
52
47
|
/**
|
|
53
48
|
* @type {ReadonlySet<"javascript" | "css-url">}
|
|
54
49
|
*/
|
|
@@ -111,7 +106,6 @@ module.exports.CSS_IMPORT_TYPES = CSS_IMPORT_TYPES;
|
|
|
111
106
|
module.exports.CSS_TYPE = CSS_TYPE;
|
|
112
107
|
module.exports.CSS_TYPES = CSS_TYPES;
|
|
113
108
|
module.exports.CSS_URL_TYPES = CSS_URL_TYPES;
|
|
114
|
-
module.exports.JS_AND_CSS_EXPORT_TYPES = JS_AND_CSS_EXPORT_TYPES;
|
|
115
109
|
module.exports.JS_AND_CSS_TYPES = JS_AND_CSS_TYPES;
|
|
116
110
|
module.exports.JS_AND_CSS_URL_TYPES = JS_AND_CSS_URL_TYPES;
|
|
117
111
|
module.exports.JS_TYPE = JS_TYPE;
|
package/lib/MultiCompiler.js
CHANGED
|
@@ -23,7 +23,7 @@ const ArrayQueue = require("./util/ArrayQueue");
|
|
|
23
23
|
* @template R
|
|
24
24
|
* @typedef {import("tapable").SyncBailHook<T, R>} SyncBailHook<T, R>
|
|
25
25
|
*/
|
|
26
|
-
/** @typedef {import("../declarations/WebpackOptions").
|
|
26
|
+
/** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
|
|
27
27
|
/** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
|
28
28
|
/** @typedef {import("./Compiler")} Compiler */
|
|
29
29
|
/**
|