webpack 5.102.1 → 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/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +25 -2
- package/lib/ConcatenationScope.js +0 -15
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +11 -11
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- 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/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- 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 +17 -16
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +115 -56
- package/lib/SourceMapDevToolPlugin.js +20 -0
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +1 -1
- package/lib/asset/AssetGenerator.js +1 -2
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/config/browserslistTargetHandler.js +5 -0
- package/lib/config/defaults.js +98 -18
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -0
- 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 +84 -34
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +97 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- 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 +23 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +97 -9
- 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/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/IdHelpers.js +4 -1
- 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 +23 -13
- package/lib/javascript/JavascriptParser.js +142 -38
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +4 -0
- 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/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/util/comparators.js +4 -3
- 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-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +16 -14
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +109 -27
- package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
- 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/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +560 -293
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
|
@@ -8,8 +8,12 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
8
8
|
const Template = require("../Template");
|
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
10
10
|
|
|
11
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
12
|
+
/** @typedef {import("../Module").ExportsType} ExportsType */
|
|
13
|
+
/** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
|
-
* @param {
|
|
16
|
+
* @param {ExportsType} exportsType exports type
|
|
13
17
|
* @returns {string} mode
|
|
14
18
|
*/
|
|
15
19
|
function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
|
|
@@ -19,61 +23,81 @@ function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
|
|
|
19
23
|
if (exportsType === "dynamic") return `/* ${exportsType} */ 3`;
|
|
20
24
|
return "";
|
|
21
25
|
}
|
|
26
|
+
|
|
22
27
|
/**
|
|
23
|
-
* @param {import("../ModuleTemplate").RuntimeTemplate} _runtimeTemplate runtimeTemplate
|
|
24
|
-
* @param {import("../Module").ExportsType} exportsType exportsType
|
|
25
28
|
* @param {string} moduleId moduleId
|
|
26
|
-
* @param {
|
|
27
|
-
* @
|
|
29
|
+
* @param {ExportsType} exportsType exportsType
|
|
30
|
+
* @param {(ModuleId | null)[]} asyncDepsIds asyncDepsIds
|
|
31
|
+
* @param {RuntimeRequirements} runtimeRequirements runtime requirements
|
|
32
|
+
* @returns {string} call make optimized deferred namespace object
|
|
28
33
|
*/
|
|
29
34
|
function getOptimizedDeferredModule(
|
|
30
|
-
_runtimeTemplate,
|
|
31
|
-
exportsType,
|
|
32
35
|
moduleId,
|
|
33
|
-
|
|
36
|
+
exportsType,
|
|
37
|
+
asyncDepsIds,
|
|
38
|
+
runtimeRequirements
|
|
34
39
|
) {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`/* ${exportsType} */ get a() {`,
|
|
41
|
-
// if exportsType is "namespace" we can generate the most optimized code,
|
|
42
|
-
// on the second access, we can avoid trigger the getter.
|
|
43
|
-
// we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
|
|
44
|
-
exportsType === "namespace" || exportsType === "dynamic"
|
|
45
|
-
? Template.indent([
|
|
46
|
-
`var exports = ${init};`,
|
|
47
|
-
`${
|
|
48
|
-
exportsType === "dynamic" ? "if (exports.__esModule) " : ""
|
|
49
|
-
}Object.defineProperty(this, "a", { value: exports });`,
|
|
50
|
-
"return exports;"
|
|
51
|
-
])
|
|
52
|
-
: Template.indent([`return ${init};`]),
|
|
53
|
-
isAsync ? "}," : "}",
|
|
54
|
-
isAsync
|
|
55
|
-
? `[${
|
|
56
|
-
RuntimeGlobals.makeDeferredNamespaceObjectSymbol
|
|
57
|
-
}]: ${JSON.stringify(asyncDepsIds.filter((x) => x !== null))}`
|
|
40
|
+
runtimeRequirements.add(RuntimeGlobals.makeOptimizedDeferredNamespaceObject);
|
|
41
|
+
const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
42
|
+
return `${RuntimeGlobals.makeOptimizedDeferredNamespaceObject}(${moduleId}, ${mode}${
|
|
43
|
+
asyncDepsIds.length > 0
|
|
44
|
+
? `, ${JSON.stringify(asyncDepsIds.filter((x) => x !== null))}`
|
|
58
45
|
: ""
|
|
59
|
-
|
|
60
|
-
return Template.asString(["{", Template.indent(props), "}"]);
|
|
46
|
+
})`;
|
|
61
47
|
}
|
|
62
48
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
49
|
+
class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
50
|
+
/**
|
|
51
|
+
* @param {boolean} hasAsyncRuntime if async module is used.
|
|
52
|
+
*/
|
|
53
|
+
constructor(hasAsyncRuntime) {
|
|
54
|
+
super("make optimized deferred namespace object");
|
|
55
|
+
this.hasAsyncRuntime = hasAsyncRuntime;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @returns {string | null} runtime code
|
|
60
|
+
*/
|
|
61
|
+
generate() {
|
|
62
|
+
if (!this.compilation) return null;
|
|
63
|
+
const fn = RuntimeGlobals.makeOptimizedDeferredNamespaceObject;
|
|
64
|
+
const hasAsync = this.hasAsyncRuntime;
|
|
65
|
+
return Template.asString([
|
|
66
|
+
// Note: must be a function (not arrow), because this is used in body!
|
|
67
|
+
`${fn} = function(moduleId, mode${hasAsync ? ", asyncDeps" : ""}) {`,
|
|
68
|
+
Template.indent([
|
|
69
|
+
"// mode: 0 => namespace (esm)",
|
|
70
|
+
"// mode: 1 => default-only (esm strict cjs)",
|
|
71
|
+
"// mode: 2 => default-with-named (esm-cjs compat)",
|
|
72
|
+
"// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
|
|
73
|
+
"var r = this;",
|
|
74
|
+
hasAsync ? "var isAsync = asyncDeps && asyncDeps.length;" : "",
|
|
75
|
+
"var obj = {",
|
|
76
|
+
Template.indent([
|
|
77
|
+
"get a() {",
|
|
78
|
+
Template.indent([
|
|
79
|
+
"var exports = r(moduleId);",
|
|
80
|
+
hasAsync
|
|
81
|
+
? `if(isAsync) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
|
|
82
|
+
: "",
|
|
83
|
+
// if exportsType is "namespace" we can generate the most optimized code,
|
|
84
|
+
// on the second access, we can avoid trigger the getter.
|
|
85
|
+
// we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
|
|
86
|
+
'if(mode == 0 || (mode == 3 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
|
|
87
|
+
"return exports;"
|
|
88
|
+
]),
|
|
89
|
+
"}"
|
|
90
|
+
]),
|
|
91
|
+
"};",
|
|
92
|
+
hasAsync
|
|
93
|
+
? `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps;`
|
|
94
|
+
: "",
|
|
95
|
+
"return obj;"
|
|
96
|
+
]),
|
|
97
|
+
"};"
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
77
101
|
|
|
78
102
|
class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
79
103
|
/**
|
|
@@ -92,8 +116,6 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
92
116
|
const { runtimeTemplate } = this.compilation;
|
|
93
117
|
const fn = RuntimeGlobals.makeDeferredNamespaceObject;
|
|
94
118
|
const hasAsync = this.hasAsyncRuntime;
|
|
95
|
-
const strictError =
|
|
96
|
-
this.compilation.options.output.strictModuleErrorHandling;
|
|
97
119
|
const init = runtimeTemplate.supportsOptionalChaining()
|
|
98
120
|
? "init?.();"
|
|
99
121
|
: "if (init) init();";
|
|
@@ -104,7 +126,18 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
104
126
|
"// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
|
|
105
127
|
"",
|
|
106
128
|
"var cachedModule = __webpack_module_cache__[moduleId];",
|
|
107
|
-
|
|
129
|
+
"if (cachedModule && cachedModule.error === undefined) {",
|
|
130
|
+
Template.indent([
|
|
131
|
+
"var exports = cachedModule.exports;",
|
|
132
|
+
hasAsync
|
|
133
|
+
? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
|
|
134
|
+
: "",
|
|
135
|
+
"if (mode == 0) return exports;",
|
|
136
|
+
`if (mode == 1) return ${RuntimeGlobals.createFakeNamespaceObject}(exports);`,
|
|
137
|
+
`if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
|
|
138
|
+
`if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
|
|
139
|
+
]),
|
|
140
|
+
"}",
|
|
108
141
|
"",
|
|
109
142
|
`var init = ${runtimeTemplate.basicFunction("", [
|
|
110
143
|
`ns = ${RuntimeGlobals.require}(moduleId);`,
|
|
@@ -137,9 +170,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
137
170
|
"}"
|
|
138
171
|
])};`,
|
|
139
172
|
"",
|
|
140
|
-
|
|
141
|
-
strictError ? "" : "cachedModule && cachedModule.exports || "
|
|
142
|
-
}__webpack_module_deferred_exports__[moduleId] || (__webpack_module_deferred_exports__[moduleId] = { __proto__: null });`,
|
|
173
|
+
"var ns = __webpack_module_deferred_exports__[moduleId] || (__webpack_module_deferred_exports__[moduleId] = { __proto__: null });",
|
|
143
174
|
"var handler = {",
|
|
144
175
|
Template.indent([
|
|
145
176
|
"__proto__: null,",
|
|
@@ -161,7 +192,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
161
192
|
'case "__esModule":',
|
|
162
193
|
"case Symbol.toStringTag:",
|
|
163
194
|
hasAsync
|
|
164
|
-
? `case ${RuntimeGlobals.
|
|
195
|
+
? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
|
|
165
196
|
: "",
|
|
166
197
|
Template.indent("return true;"),
|
|
167
198
|
'case "then":',
|
|
@@ -208,7 +239,10 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
208
239
|
}
|
|
209
240
|
}
|
|
210
241
|
|
|
211
|
-
module.exports =
|
|
242
|
+
module.exports.MakeDeferredNamespaceObjectRuntimeModule =
|
|
243
|
+
MakeDeferredNamespaceObjectRuntimeModule;
|
|
244
|
+
module.exports.MakeOptimizedDeferredNamespaceObjectRuntimeModule =
|
|
245
|
+
MakeOptimizedDeferredNamespaceObjectRuntimeModule;
|
|
212
246
|
module.exports.getMakeDeferredNamespaceModeFromExportsType =
|
|
213
247
|
getMakeDeferredNamespaceModeFromExportsType;
|
|
214
248
|
module.exports.getOptimizedDeferredModule = getOptimizedDeferredModule;
|
package/lib/util/comparators.js
CHANGED
|
@@ -19,6 +19,7 @@ const { compareRuntime } = require("./runtime");
|
|
|
19
19
|
/** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
|
|
20
20
|
/** @typedef {import("../Module")} Module */
|
|
21
21
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
22
|
+
/** @typedef {import("../dependencies/ModuleDependency")} ModuleDependency */
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @typedef {object} DependencySourceOrder
|
|
@@ -524,9 +525,9 @@ const sortWithSourceOrder = (dependencies, dependencySourceOrderMap) => {
|
|
|
524
525
|
);
|
|
525
526
|
return main;
|
|
526
527
|
}
|
|
527
|
-
return /** @type {
|
|
528
|
-
dep
|
|
529
|
-
)
|
|
528
|
+
return /** @type {number} */ (
|
|
529
|
+
/** @type {ModuleDependency} */ (dep).sourceOrder
|
|
530
|
+
);
|
|
530
531
|
};
|
|
531
532
|
|
|
532
533
|
/**
|
|
@@ -73,10 +73,10 @@ module.exports = {
|
|
|
73
73
|
require("../dependencies/CriticalDependencyWarning"),
|
|
74
74
|
"dependencies/CssImportDependency": () =>
|
|
75
75
|
require("../dependencies/CssImportDependency"),
|
|
76
|
-
"dependencies/
|
|
77
|
-
require("../dependencies/
|
|
78
|
-
"dependencies/
|
|
79
|
-
require("../dependencies/
|
|
76
|
+
"dependencies/CssIcssLocalIdentifierDependency": () =>
|
|
77
|
+
require("../dependencies/CssIcssLocalIdentifierDependency"),
|
|
78
|
+
"dependencies/CssIcssSelfLocalIdentifierDependency": () =>
|
|
79
|
+
require("../dependencies/CssIcssSelfLocalIdentifierDependency"),
|
|
80
80
|
"dependencies/CssIcssImportDependency": () =>
|
|
81
81
|
require("../dependencies/CssIcssImportDependency"),
|
|
82
82
|
"dependencies/CssIcssExportDependency": () =>
|
|
@@ -77,7 +77,6 @@ class EnableWasmLoadingPlugin {
|
|
|
77
77
|
switch (type) {
|
|
78
78
|
case "fetch": {
|
|
79
79
|
if (compiler.options.experiments.syncWebAssembly) {
|
|
80
|
-
// TODO webpack 6 remove FetchCompileWasmPlugin
|
|
81
80
|
const FetchCompileWasmPlugin = require("../web/FetchCompileWasmPlugin");
|
|
82
81
|
|
|
83
82
|
new FetchCompileWasmPlugin({
|
|
@@ -95,7 +94,6 @@ class EnableWasmLoadingPlugin {
|
|
|
95
94
|
}
|
|
96
95
|
case "async-node": {
|
|
97
96
|
if (compiler.options.experiments.syncWebAssembly) {
|
|
98
|
-
// TODO webpack 6 remove ReadFileCompileWasmPlugin
|
|
99
97
|
const ReadFileCompileWasmPlugin = require("../node/ReadFileCompileWasmPlugin");
|
|
100
98
|
|
|
101
99
|
new ReadFileCompileWasmPlugin({
|
|
@@ -119,9 +117,17 @@ class EnableWasmLoadingPlugin {
|
|
|
119
117
|
break;
|
|
120
118
|
}
|
|
121
119
|
case "universal": {
|
|
122
|
-
|
|
120
|
+
if (compiler.options.experiments.syncWebAssembly) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
"Universal wasm loading type is only supported by asynchronous web assembly."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
if (compiler.options.experiments.asyncWebAssembly) {
|
|
127
|
+
const UniversalCompileAsyncWasmPlugin = require("../wasm-async/UniversalCompileAsyncWasmPlugin");
|
|
128
|
+
|
|
129
|
+
new UniversalCompileAsyncWasmPlugin().apply(compiler);
|
|
130
|
+
}
|
|
125
131
|
break;
|
|
126
132
|
}
|
|
127
133
|
default:
|
|
@@ -20,7 +20,7 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
|
|
|
20
20
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* @typedef {{ request: string, importVar: string }} ImportObjRequestItem
|
|
23
|
+
* @typedef {{ request: string, importVar: string, dependency: WebAssemblyImportDependency }} ImportObjRequestItem
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
@@ -70,7 +70,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
70
70
|
if (!depModules.has(module)) {
|
|
71
71
|
depModules.set(module, {
|
|
72
72
|
request: dep.request,
|
|
73
|
-
importVar: `WEBPACK_IMPORTED_MODULE_${depModules.size}
|
|
73
|
+
importVar: `WEBPACK_IMPORTED_MODULE_${depModules.size}`,
|
|
74
|
+
dependency: dep
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
let list = wasmDepsByRequest.get(dep.request);
|
|
@@ -87,7 +88,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
87
88
|
|
|
88
89
|
const importStatements = Array.from(
|
|
89
90
|
depModules,
|
|
90
|
-
([importedModule, { request, importVar }]) => {
|
|
91
|
+
([importedModule, { request, importVar, dependency }]) => {
|
|
91
92
|
if (moduleGraph.isAsync(importedModule)) {
|
|
92
93
|
promises.push(importVar);
|
|
93
94
|
}
|
|
@@ -99,7 +100,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
99
100
|
request,
|
|
100
101
|
originModule: module,
|
|
101
102
|
importVar,
|
|
102
|
-
runtimeRequirements
|
|
103
|
+
runtimeRequirements,
|
|
104
|
+
dependency
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
);
|
|
@@ -132,7 +134,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
132
134
|
importVar,
|
|
133
135
|
initFragments,
|
|
134
136
|
runtime,
|
|
135
|
-
runtimeRequirements
|
|
137
|
+
runtimeRequirements,
|
|
138
|
+
dependency: dep
|
|
136
139
|
})}`;
|
|
137
140
|
});
|
|
138
141
|
return Template.asString([
|
|
@@ -71,6 +71,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
71
71
|
importedModules.set(
|
|
72
72
|
moduleGraph.getModule(dep),
|
|
73
73
|
(importData = {
|
|
74
|
+
dependency: moduleDep,
|
|
74
75
|
importVar: `m${index}`,
|
|
75
76
|
index,
|
|
76
77
|
request: (moduleDep && moduleDep.userRequest) || undefined,
|
|
@@ -106,7 +107,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
106
107
|
defaultInterop: true,
|
|
107
108
|
initFragments,
|
|
108
109
|
runtime,
|
|
109
|
-
runtimeRequirements
|
|
110
|
+
runtimeRequirements,
|
|
111
|
+
dependency: dep
|
|
110
112
|
})
|
|
111
113
|
);
|
|
112
114
|
}
|
|
@@ -138,7 +140,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
138
140
|
defaultInterop: true,
|
|
139
141
|
initFragments,
|
|
140
142
|
runtime,
|
|
141
|
-
runtimeRequirements
|
|
143
|
+
runtimeRequirements,
|
|
144
|
+
dependency: dep
|
|
142
145
|
})};`,
|
|
143
146
|
`if(WebAssembly.Global) ${exportProp} = ` +
|
|
144
147
|
`new WebAssembly.Global({ value: ${JSON.stringify(
|
|
@@ -154,7 +157,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
154
157
|
const importsCode = Template.asString(
|
|
155
158
|
Array.from(
|
|
156
159
|
importedModules,
|
|
157
|
-
([module, { importVar, request, reexports }]) => {
|
|
160
|
+
([module, { importVar, request, reexports, dependency }]) => {
|
|
158
161
|
const importStatement = runtimeTemplate.importStatement({
|
|
159
162
|
module,
|
|
160
163
|
moduleGraph,
|
|
@@ -162,7 +165,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
162
165
|
request,
|
|
163
166
|
importVar,
|
|
164
167
|
originModule: module,
|
|
165
|
-
runtimeRequirements
|
|
168
|
+
runtimeRequirements,
|
|
169
|
+
dependency
|
|
166
170
|
});
|
|
167
171
|
return importStatement[0] + importStatement[1] + reexports.join("\n");
|
|
168
172
|
}
|
|
@@ -17,8 +17,6 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
|
|
|
17
17
|
* @property {boolean=} mangleImports mangle imports
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
// TODO webpack 6 remove
|
|
21
|
-
|
|
22
20
|
const PLUGIN_NAME = "FetchCompileWasmPlugin";
|
|
23
21
|
|
|
24
22
|
class FetchCompileWasmPlugin {
|
package/lib/webpack.js
CHANGED
|
@@ -106,107 +106,110 @@ const createCompiler = (rawOptions, compilerIndex) => {
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
* @
|
|
109
|
+
* @template T
|
|
110
|
+
* @param {T[] | T} options options
|
|
111
|
+
* @returns {T[]} array of options
|
|
112
|
+
*/
|
|
113
|
+
const asArray = (options) =>
|
|
114
|
+
Array.isArray(options) ? [...options] : [options];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @overload
|
|
110
118
|
* @param {WebpackOptions} options options object
|
|
111
|
-
* @param {Callback<Stats
|
|
119
|
+
* @param {Callback<Stats>} callback callback
|
|
112
120
|
* @returns {Compiler | null} the compiler object
|
|
113
121
|
*/
|
|
114
|
-
|
|
115
122
|
/**
|
|
116
|
-
* @
|
|
123
|
+
* @overload
|
|
124
|
+
* @param {WebpackOptions} options options object
|
|
125
|
+
* @returns {Compiler} the compiler object
|
|
126
|
+
*/
|
|
127
|
+
/**
|
|
128
|
+
* @overload
|
|
117
129
|
* @param {MultiWebpackOptions} options options objects
|
|
118
|
-
* @param {Callback<MultiStats
|
|
130
|
+
* @param {Callback<MultiStats>} callback callback
|
|
119
131
|
* @returns {MultiCompiler | null} the multi compiler object
|
|
120
132
|
*/
|
|
121
|
-
|
|
122
133
|
/**
|
|
123
|
-
* @
|
|
124
|
-
* @param {
|
|
125
|
-
* @returns {
|
|
134
|
+
* @overload
|
|
135
|
+
* @param {MultiWebpackOptions} options options objects
|
|
136
|
+
* @returns {MultiCompiler} the multi compiler object
|
|
126
137
|
*/
|
|
127
|
-
const asArray = (options) =>
|
|
128
|
-
Array.isArray(options) ? [...options] : [options];
|
|
129
|
-
|
|
130
138
|
/**
|
|
131
|
-
* @callback WebpackCallback
|
|
132
139
|
* @param {WebpackOptions | MultiWebpackOptions} options options
|
|
133
140
|
* @param {Callback<Stats> & Callback<MultiStats>=} callback callback
|
|
134
141
|
* @returns {Compiler | MultiCompiler | null} Compiler or MultiCompiler
|
|
135
142
|
*/
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
/** @type {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
/** @type {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
);
|
|
166
|
-
watch = options.some((options) => options.watch);
|
|
167
|
-
watchOptions = options.map((options) => options.watchOptions || {});
|
|
168
|
-
} else {
|
|
169
|
-
const webpackOptions = /** @type {WebpackOptions} */ (options);
|
|
170
|
-
/** @type {Compiler} */
|
|
171
|
-
compiler = createCompiler(webpackOptions);
|
|
172
|
-
watch = webpackOptions.watch;
|
|
173
|
-
watchOptions = webpackOptions.watchOptions || {};
|
|
174
|
-
}
|
|
175
|
-
return { compiler, watch, watchOptions };
|
|
176
|
-
};
|
|
177
|
-
if (callback) {
|
|
178
|
-
try {
|
|
179
|
-
const { compiler, watch, watchOptions } = create();
|
|
180
|
-
if (watch) {
|
|
181
|
-
compiler.watch(watchOptions, callback);
|
|
182
|
-
} else {
|
|
183
|
-
compiler.run((err, stats) => {
|
|
184
|
-
compiler.close((err2) => {
|
|
185
|
-
callback(
|
|
186
|
-
err || err2,
|
|
187
|
-
/** @type {options extends WebpackOptions ? Stats : MultiStats} */
|
|
188
|
-
(stats)
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
return compiler;
|
|
194
|
-
} catch (err) {
|
|
195
|
-
process.nextTick(() => callback(/** @type {Error} */ (err)));
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
143
|
+
const webpack = (options, callback) => {
|
|
144
|
+
const create = () => {
|
|
145
|
+
if (
|
|
146
|
+
!asArray(/** @type {WebpackOptions} */ (options)).every(
|
|
147
|
+
webpackOptionsSchemaCheck
|
|
148
|
+
)
|
|
149
|
+
) {
|
|
150
|
+
getValidateSchema()(webpackOptionsSchema, options);
|
|
151
|
+
util.deprecate(
|
|
152
|
+
() => {},
|
|
153
|
+
"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
|
|
154
|
+
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
|
|
155
|
+
)();
|
|
156
|
+
}
|
|
157
|
+
/** @type {MultiCompiler|Compiler} */
|
|
158
|
+
let compiler;
|
|
159
|
+
/** @type {boolean | undefined} */
|
|
160
|
+
let watch = false;
|
|
161
|
+
/** @type {WatchOptions | WatchOptions[]} */
|
|
162
|
+
let watchOptions;
|
|
163
|
+
if (Array.isArray(options)) {
|
|
164
|
+
/** @type {MultiCompiler} */
|
|
165
|
+
compiler = createMultiCompiler(
|
|
166
|
+
options,
|
|
167
|
+
/** @type {MultiCompilerOptions} */
|
|
168
|
+
(options)
|
|
169
|
+
);
|
|
170
|
+
watch = options.some((options) => options.watch);
|
|
171
|
+
watchOptions = options.map((options) => options.watchOptions || {});
|
|
198
172
|
} else {
|
|
199
|
-
const
|
|
173
|
+
const webpackOptions = /** @type {WebpackOptions} */ (options);
|
|
174
|
+
/** @type {Compiler} */
|
|
175
|
+
compiler = createCompiler(webpackOptions);
|
|
176
|
+
watch = webpackOptions.watch;
|
|
177
|
+
watchOptions = webpackOptions.watchOptions || {};
|
|
178
|
+
}
|
|
179
|
+
return { compiler, watch, watchOptions };
|
|
180
|
+
};
|
|
181
|
+
if (callback) {
|
|
182
|
+
try {
|
|
183
|
+
const { compiler, watch, watchOptions } = create();
|
|
200
184
|
if (watch) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
185
|
+
compiler.watch(watchOptions, callback);
|
|
186
|
+
} else {
|
|
187
|
+
compiler.run((err, stats) => {
|
|
188
|
+
compiler.close((err2) => {
|
|
189
|
+
callback(
|
|
190
|
+
err || err2,
|
|
191
|
+
/** @type {options extends WebpackOptions ? Stats : MultiStats} */
|
|
192
|
+
(stats)
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
206
196
|
}
|
|
207
197
|
return compiler;
|
|
198
|
+
} catch (err) {
|
|
199
|
+
process.nextTick(() => callback(/** @type {Error} */ (err)));
|
|
200
|
+
return null;
|
|
208
201
|
}
|
|
202
|
+
} else {
|
|
203
|
+
const { compiler, watch } = create();
|
|
204
|
+
if (watch) {
|
|
205
|
+
util.deprecate(
|
|
206
|
+
() => {},
|
|
207
|
+
"A 'callback' argument needs to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.",
|
|
208
|
+
"DEP_WEBPACK_WATCH_WITHOUT_CALLBACK"
|
|
209
|
+
)();
|
|
210
|
+
}
|
|
211
|
+
return compiler;
|
|
209
212
|
}
|
|
210
|
-
|
|
213
|
+
};
|
|
211
214
|
|
|
212
215
|
module.exports = webpack;
|
package/module.d.ts
CHANGED
|
@@ -161,10 +161,15 @@ declare namespace webpack {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
interface ImportMetaEnv {
|
|
165
|
+
[key: string]: string | boolean | undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
164
168
|
interface ImportMeta {
|
|
165
169
|
url: string;
|
|
166
170
|
webpack: number;
|
|
167
171
|
webpackHot: webpack.Hot;
|
|
172
|
+
env: ImportMetaEnv;
|
|
168
173
|
webpackContext: (
|
|
169
174
|
request: string,
|
|
170
175
|
options?: {
|