webpack 5.83.1 → 5.85.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 +2 -2
- package/lib/AsyncDependenciesBlock.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +4 -0
- package/lib/CacheFacade.js +4 -0
- package/lib/ChunkGroup.js +5 -1
- package/lib/CleanPlugin.js +30 -7
- package/lib/CompatibilityPlugin.js +4 -3
- package/lib/Compilation.js +3 -3
- package/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +11 -2
- package/lib/DllEntryPlugin.js +5 -0
- package/lib/DllModule.js +1 -1
- package/lib/DllModuleFactory.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/HookWebpackError.js +1 -1
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -9
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleTypeConstants.js +2 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +4 -2
- package/lib/NullFactory.js +1 -1
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RuntimeModule.js +5 -5
- package/lib/RuntimePlugin.js +4 -0
- package/lib/RuntimeTemplate.js +7 -7
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +9 -2
- package/lib/Template.js +3 -2
- package/lib/UseStrictPlugin.js +4 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/asset/AssetGenerator.js +7 -2
- package/lib/asset/AssetModulesPlugin.js +7 -1
- package/lib/asset/AssetParser.js +4 -1
- package/lib/asset/RawDataUrlModule.js +5 -3
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +7 -1
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +240 -73
- package/lib/config/normalization.js +104 -71
- package/lib/config/target.js +37 -10
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/FallbackDependency.js +7 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +5 -1
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +4 -0
- package/lib/container/RemoteRuntimeModule.js +2 -1
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/css/CssParser.js +168 -73
- package/lib/debug/ProfilingPlugin.js +11 -0
- package/lib/dependencies/AMDDefineDependency.js +12 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
- package/lib/dependencies/AMDPlugin.js +7 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
- package/lib/dependencies/AMDRequireContextDependency.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +8 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/CachedConstDependency.js +6 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
- package/lib/dependencies/CommonJsExportsDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
- package/lib/dependencies/CommonJsPlugin.js +28 -12
- package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
- package/lib/dependencies/ConstDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +12 -2
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyExports.js +3 -1
- package/lib/dependencies/HarmonyImportDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +86 -6
- package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
- package/lib/dependencies/ImportContextDependency.js +6 -0
- package/lib/dependencies/ImportDependency.js +2 -1
- package/lib/dependencies/ImportEagerDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportParserPlugin.js +5 -0
- package/lib/dependencies/ImportPlugin.js +7 -0
- package/lib/dependencies/ImportWeakDependency.js +2 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +7 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +2 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextPlugin.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
- package/lib/dependencies/RequireEnsureDependency.js +8 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +14 -0
- package/lib/dependencies/RequireHeaderDependency.js +5 -1
- package/lib/dependencies/RequireIncludeDependency.js +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireIncludePlugin.js +14 -0
- package/lib/dependencies/RequireResolveContextDependency.js +8 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
- package/lib/dependencies/SystemPlugin.js +10 -1
- package/lib/dependencies/URLDependency.js +3 -2
- package/lib/dependencies/URLPlugin.js +7 -5
- package/lib/dependencies/UnsupportedDependency.js +5 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
- package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
- package/lib/dependencies/WorkerDependency.js +2 -1
- package/lib/dependencies/WorkerPlugin.js +30 -3
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +15 -7
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +14 -9
- package/lib/hmr/LazyCompilationPlugin.js +1 -1
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +8 -1
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +11 -1
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +36 -31
- package/lib/javascript/JavascriptParser.js +586 -192
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +7 -5
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AssignLibraryPlugin.js +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +6 -3
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +6 -3
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -3
- package/lib/optimize/ConcatenatedModule.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
- package/lib/runtime/BaseUriRuntimeModule.js +5 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +5 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +4 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +8 -5
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +21 -0
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +20 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +23 -0
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/serialization.js +10 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -2
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
- package/lib/web/FetchCompileWasmPlugin.js +19 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -2
- package/package.json +3 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/types.d.ts +655 -290
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
const { register } = require("./serialization");
|
8
8
|
|
9
|
+
/** @typedef {import("../serialization/ObjectMiddleware").Constructor} Constructor */
|
10
|
+
|
9
11
|
class ClassSerializer {
|
10
12
|
constructor(Constructor) {
|
11
13
|
this.Constructor = Constructor;
|
@@ -25,6 +27,11 @@ class ClassSerializer {
|
|
25
27
|
}
|
26
28
|
}
|
27
29
|
|
30
|
+
/**
|
31
|
+
* @param {Constructor} Constructor the constructor
|
32
|
+
* @param {string} request the request which will be required when deserializing
|
33
|
+
* @param {string | null} [name] the name to make multiple serializer unique when sharing a request
|
34
|
+
*/
|
28
35
|
module.exports = (Constructor, request, name = null) => {
|
29
36
|
register(Constructor, request, name, new ClassSerializer(Constructor));
|
30
37
|
};
|
@@ -11,6 +11,8 @@ const memoize = require("./memoize");
|
|
11
11
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
12
12
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
13
13
|
/** @typedef {import("../serialization/Serializer")} Serializer */
|
14
|
+
/** @typedef {typeof import("../util/Hash")} Hash */
|
15
|
+
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
14
16
|
|
15
17
|
const getBinaryMiddleware = memoize(() =>
|
16
18
|
require("../serialization/BinaryMiddleware")
|
@@ -72,6 +74,9 @@ module.exports = {
|
|
72
74
|
get MEASURE_END_OPERATION() {
|
73
75
|
return getBinaryMiddleware().MEASURE_END_OPERATION;
|
74
76
|
},
|
77
|
+
/**
|
78
|
+
* @returns {Serializer} buffer serializer
|
79
|
+
*/
|
75
80
|
get buffersSerializer() {
|
76
81
|
if (buffersSerializer !== undefined) return buffersSerializer;
|
77
82
|
registerSerializers();
|
@@ -93,6 +98,11 @@ module.exports = {
|
|
93
98
|
binaryMiddleware
|
94
99
|
]));
|
95
100
|
},
|
101
|
+
/**
|
102
|
+
* @param {IntermediateFileSystem} fs filesystem
|
103
|
+
* @param {string | Hash} hashFunction hash function to use
|
104
|
+
* @returns {Serializer} file serializer
|
105
|
+
*/
|
96
106
|
createFileSerializer: (fs, hashFunction) => {
|
97
107
|
registerSerializers();
|
98
108
|
const Serializer = getSerializer();
|
@@ -9,7 +9,16 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
|
+
/**
|
13
|
+
* @typedef {Object} AsyncWasmLoadingRuntimeModuleOptions
|
14
|
+
* @property {function(string): string} generateLoadBinaryCode
|
15
|
+
* @property {boolean} supportsStreaming
|
16
|
+
*/
|
17
|
+
|
12
18
|
class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
|
19
|
+
/**
|
20
|
+
* @param {AsyncWasmLoadingRuntimeModuleOptions} options options
|
21
|
+
*/
|
13
22
|
constructor({ generateLoadBinaryCode, supportsStreaming }) {
|
14
23
|
super("wasm loading", RuntimeModule.STAGE_NORMAL);
|
15
24
|
this.generateLoadBinaryCode = generateLoadBinaryCode;
|
@@ -13,7 +13,15 @@ const Generator = require("../Generator");
|
|
13
13
|
|
14
14
|
const TYPES = new Set(["webassembly"]);
|
15
15
|
|
16
|
+
/**
|
17
|
+
* @typedef {Object} AsyncWebAssemblyGeneratorOptions
|
18
|
+
* @property {boolean} [mangleImports] mangle imports
|
19
|
+
*/
|
20
|
+
|
16
21
|
class AsyncWebAssemblyGenerator extends Generator {
|
22
|
+
/**
|
23
|
+
* @param {AsyncWebAssemblyGeneratorOptions} options options
|
24
|
+
*/
|
17
25
|
constructor(options) {
|
18
26
|
super();
|
19
27
|
this.options = options;
|
@@ -46,7 +54,7 @@ class AsyncWebAssemblyGenerator extends Generator {
|
|
46
54
|
* @returns {Source} generated code
|
47
55
|
*/
|
48
56
|
generate(module, generateContext) {
|
49
|
-
return module.originalSource();
|
57
|
+
return /** @type {Source} */ (module.originalSource());
|
50
58
|
}
|
51
59
|
}
|
52
60
|
|
@@ -13,6 +13,7 @@ const Template = require("../Template");
|
|
13
13
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
14
14
|
|
15
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
16
17
|
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
|
17
18
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
18
19
|
/** @typedef {import("../Module")} Module */
|
@@ -21,7 +22,14 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
|
|
21
22
|
|
22
23
|
const TYPES = new Set(["webassembly"]);
|
23
24
|
|
25
|
+
/**
|
26
|
+
* @typedef {{ request: string, importVar: string }} ImportObjRequestItem
|
27
|
+
*/
|
28
|
+
|
24
29
|
class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
30
|
+
/**
|
31
|
+
* @param {OutputOptions["webassemblyModuleFilename"]} filenameTemplate template for the WebAssembly module filename
|
32
|
+
*/
|
25
33
|
constructor(filenameTemplate) {
|
26
34
|
super();
|
27
35
|
this.filenameTemplate = filenameTemplate;
|
@@ -61,9 +69,9 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
61
69
|
runtimeRequirements.add(RuntimeGlobals.moduleId);
|
62
70
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
63
71
|
runtimeRequirements.add(RuntimeGlobals.instantiateWasm);
|
64
|
-
/** @type {InitFragment[]} */
|
72
|
+
/** @type {InitFragment<InitFragment<string>>[]} */
|
65
73
|
const initFragments = [];
|
66
|
-
/** @type {Map<Module,
|
74
|
+
/** @type {Map<Module, ImportObjRequestItem>} */
|
67
75
|
const depModules = new Map();
|
68
76
|
/** @type {Map<string, WebAssemblyImportDependency[]>} */
|
69
77
|
const wasmDepsByRequest = new Map();
|
@@ -113,7 +121,9 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
113
121
|
([request, deps]) => {
|
114
122
|
const exportItems = deps.map(dep => {
|
115
123
|
const importedModule = moduleGraph.getModule(dep);
|
116
|
-
const importVar =
|
124
|
+
const importVar =
|
125
|
+
/** @type {ImportObjRequestItem} */
|
126
|
+
(depModules.get(importedModule)).importVar;
|
117
127
|
return `${JSON.stringify(
|
118
128
|
dep.name
|
119
129
|
)}: ${runtimeTemplate.exportFromImport({
|
@@ -15,6 +15,7 @@ const { compareModulesByIdentifier } = require("../util/comparators");
|
|
15
15
|
const memoize = require("../util/memoize");
|
16
16
|
|
17
17
|
/** @typedef {import("webpack-sources").Source} Source */
|
18
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
18
19
|
/** @typedef {import("../Chunk")} Chunk */
|
19
20
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
20
21
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
@@ -25,6 +26,7 @@ const memoize = require("../util/memoize");
|
|
25
26
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
26
27
|
/** @typedef {import("../Template").RenderManifestEntry} RenderManifestEntry */
|
27
28
|
/** @typedef {import("../Template").RenderManifestOptions} RenderManifestOptions */
|
29
|
+
/** @typedef {import("../WebpackError")} WebpackError */
|
28
30
|
|
29
31
|
const getAsyncWebAssemblyGenerator = memoize(() =>
|
30
32
|
require("./AsyncWebAssemblyGenerator")
|
@@ -51,6 +53,11 @@ const getAsyncWebAssemblyParser = memoize(() =>
|
|
51
53
|
* @property {SyncWaterfallHook<[Source, Module, WebAssemblyRenderContext]>} renderModuleContent
|
52
54
|
*/
|
53
55
|
|
56
|
+
/**
|
57
|
+
* @typedef {Object} AsyncWebAssemblyModulesPluginOptions
|
58
|
+
* @property {boolean} [mangleImports] mangle imports
|
59
|
+
*/
|
60
|
+
|
54
61
|
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
55
62
|
const compilationHooksMap = new WeakMap();
|
56
63
|
|
@@ -81,6 +88,9 @@ class AsyncWebAssemblyModulesPlugin {
|
|
81
88
|
return hooks;
|
82
89
|
}
|
83
90
|
|
91
|
+
/**
|
92
|
+
* @param {AsyncWebAssemblyModulesPluginOptions} options options
|
93
|
+
*/
|
84
94
|
constructor(options) {
|
85
95
|
this.options = options;
|
86
96
|
}
|
@@ -140,7 +150,8 @@ class AsyncWebAssemblyModulesPlugin {
|
|
140
150
|
)) {
|
141
151
|
if (module.type === WEBASSEMBLY_MODULE_TYPE_ASYNC) {
|
142
152
|
const filenameTemplate =
|
143
|
-
|
153
|
+
/** @type {NonNullable<OutputOptions["webassemblyModuleFilename"]>} */
|
154
|
+
(outputOptions.webassemblyModuleFilename);
|
144
155
|
|
145
156
|
result.push({
|
146
157
|
render: () =>
|
@@ -178,6 +189,12 @@ class AsyncWebAssemblyModulesPlugin {
|
|
178
189
|
);
|
179
190
|
}
|
180
191
|
|
192
|
+
/**
|
193
|
+
* @param {Module} module the rendered module
|
194
|
+
* @param {WebAssemblyRenderContext} renderContext options object
|
195
|
+
* @param {CompilationHooks} hooks hooks
|
196
|
+
* @returns {Source} the newly generated source from rendering
|
197
|
+
*/
|
181
198
|
renderModule(module, renderContext, hooks) {
|
182
199
|
const { codeGenerationResults, chunk } = renderContext;
|
183
200
|
try {
|
@@ -192,7 +209,7 @@ class AsyncWebAssemblyModulesPlugin {
|
|
192
209
|
"AsyncWebAssemblyModulesPlugin.getCompilationHooks().renderModuleContent"
|
193
210
|
);
|
194
211
|
} catch (e) {
|
195
|
-
e.module = module;
|
212
|
+
/** @type {WebpackError} */ (e).module = module;
|
196
213
|
throw e;
|
197
214
|
}
|
198
215
|
}
|
@@ -10,14 +10,22 @@ const Template = require("../Template");
|
|
10
10
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
11
11
|
const WebAssemblyUtils = require("./WebAssemblyUtils");
|
12
12
|
|
13
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
15
|
/** @typedef {import("../Compilation")} Compilation */
|
15
16
|
/** @typedef {import("../Module")} Module */
|
17
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
18
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
17
19
|
|
18
20
|
// TODO webpack 6 remove the whole folder
|
19
21
|
|
20
22
|
// Get all wasm modules
|
23
|
+
/**
|
24
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
25
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
26
|
+
* @param {Chunk} chunk the chunk
|
27
|
+
* @returns {Module[]} all wasm modules
|
28
|
+
*/
|
21
29
|
const getAllWasmModules = (moduleGraph, chunkGraph, chunk) => {
|
22
30
|
const wasmModules = chunk.getAllAsyncChunks();
|
23
31
|
const array = [];
|
@@ -39,7 +47,7 @@ const getAllWasmModules = (moduleGraph, chunkGraph, chunk) => {
|
|
39
47
|
* generates the import object function for a module
|
40
48
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
41
49
|
* @param {Module} module the module
|
42
|
-
* @param {boolean} mangle mangle imports
|
50
|
+
* @param {boolean | undefined} mangle mangle imports
|
43
51
|
* @param {string[]} declarations array where declarations are pushed to
|
44
52
|
* @param {RuntimeSpec} runtime the runtime
|
45
53
|
* @returns {string} source code
|
@@ -188,7 +196,18 @@ const generateImportObject = (
|
|
188
196
|
}
|
189
197
|
};
|
190
198
|
|
199
|
+
/**
|
200
|
+
* @typedef {Object} WasmChunkLoadingRuntimeModuleOptions
|
201
|
+
* @property {(path: string) => string} generateLoadBinaryCode
|
202
|
+
* @property {boolean} [supportsStreaming]
|
203
|
+
* @property {boolean} [mangleImports]
|
204
|
+
* @property {Set<string>} runtimeRequirements
|
205
|
+
*/
|
206
|
+
|
191
207
|
class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
208
|
+
/**
|
209
|
+
* @param {WasmChunkLoadingRuntimeModuleOptions} options options
|
210
|
+
*/
|
192
211
|
constructor({
|
193
212
|
generateLoadBinaryCode,
|
194
213
|
supportsStreaming,
|
@@ -213,6 +232,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
213
232
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
214
233
|
);
|
215
234
|
const wasmModules = getAllWasmModules(moduleGraph, chunkGraph, chunk);
|
235
|
+
/** @type {string[]} */
|
216
236
|
const declarations = [];
|
217
237
|
const importObjects = wasmModules.map(module => {
|
218
238
|
return generateImportObject(
|
@@ -226,6 +246,10 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
226
246
|
const chunkModuleIdMap = chunkGraph.getChunkModuleIdMap(chunk, m =>
|
227
247
|
m.type.startsWith("webassembly")
|
228
248
|
);
|
249
|
+
/**
|
250
|
+
* @param {string} content content
|
251
|
+
* @returns {string} created import object
|
252
|
+
*/
|
229
253
|
const createImportObject = content =>
|
230
254
|
mangleImports
|
231
255
|
? `{ ${JSON.stringify(WebAssemblyUtils.MANGLED_MODULE)}: ${content} }`
|
@@ -9,6 +9,8 @@ const formatLocation = require("../formatLocation");
|
|
9
9
|
const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeatureError");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
|
+
/** @typedef {import("../Dependency")} Dependency */
|
13
|
+
/** @typedef {import("../Module")} Module */
|
12
14
|
|
13
15
|
class WasmFinalizeExportsPlugin {
|
14
16
|
/**
|
@@ -37,12 +39,13 @@ class WasmFinalizeExportsPlugin {
|
|
37
39
|
// 2. is active and referenced by a non-WebAssembly module
|
38
40
|
if (
|
39
41
|
connection.isTargetActive(undefined) &&
|
40
|
-
|
42
|
+
/** @type {Module} */
|
43
|
+
(connection.originModule).type.startsWith("webassembly") ===
|
41
44
|
false
|
42
45
|
) {
|
43
46
|
const referencedExports =
|
44
47
|
compilation.getDependencyReferencedExports(
|
45
|
-
connection.dependency,
|
48
|
+
/** @type {Dependency} */ (connection.dependency),
|
46
49
|
undefined
|
47
50
|
);
|
48
51
|
|
@@ -61,9 +64,15 @@ class WasmFinalizeExportsPlugin {
|
|
61
64
|
// 4. error
|
62
65
|
const error = new UnsupportedWebAssemblyFeatureError(
|
63
66
|
`Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` +
|
64
|
-
`It's used from ${
|
65
|
-
|
66
|
-
|
67
|
+
`It's used from ${
|
68
|
+
/** @type {Module} */
|
69
|
+
(connection.originModule).readableIdentifier(
|
70
|
+
compilation.requestShortener
|
71
|
+
)
|
72
|
+
} at ${formatLocation(
|
73
|
+
/** @type {Dependency} */ (connection.dependency)
|
74
|
+
.loc
|
75
|
+
)}.`
|
67
76
|
);
|
68
77
|
error.module = module;
|
69
78
|
compilation.errors.push(error);
|
@@ -27,7 +27,7 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
|
|
27
27
|
/** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */
|
28
28
|
|
29
29
|
/**
|
30
|
-
* @typedef {(ArrayBuffer) => ArrayBuffer} ArrayBufferTransform
|
30
|
+
* @typedef {(buf: ArrayBuffer) => ArrayBuffer} ArrayBufferTransform
|
31
31
|
*/
|
32
32
|
|
33
33
|
/**
|
@@ -62,9 +62,10 @@ const removeStartFunc = state => bin => {
|
|
62
62
|
* Get imported globals
|
63
63
|
*
|
64
64
|
* @param {Object} ast Module's AST
|
65
|
-
* @returns {
|
65
|
+
* @returns {t.ModuleImport[]} - nodes
|
66
66
|
*/
|
67
67
|
const getImportedGlobals = ast => {
|
68
|
+
/** @type {t.ModuleImport[]} */
|
68
69
|
const importedGlobals = [];
|
69
70
|
|
70
71
|
t.traverse(ast, {
|
@@ -318,7 +319,10 @@ const addInitFunction =
|
|
318
319
|
`${importedGlobal.module}.${importedGlobal.name}`
|
319
320
|
);
|
320
321
|
|
321
|
-
return t.funcParam(
|
322
|
+
return t.funcParam(
|
323
|
+
/** @type {string} */ (importedGlobal.descr.valtype),
|
324
|
+
id
|
325
|
+
);
|
322
326
|
});
|
323
327
|
|
324
328
|
const funcBody = [];
|
@@ -344,6 +348,7 @@ const addInitFunction =
|
|
344
348
|
|
345
349
|
funcBody.push(t.instruction("end"));
|
346
350
|
|
351
|
+
/** @type {string[]} */
|
347
352
|
const funcResults = [];
|
348
353
|
|
349
354
|
// Code section
|
@@ -369,7 +374,7 @@ const addInitFunction =
|
|
369
374
|
* Extract mangle mappings from module
|
370
375
|
* @param {ModuleGraph} moduleGraph module graph
|
371
376
|
* @param {Module} module current module
|
372
|
-
* @param {boolean} mangle mangle imports
|
377
|
+
* @param {boolean | undefined} mangle mangle imports
|
373
378
|
* @returns {Map<string, UsedWasmDependency>} mappings to mangled names
|
374
379
|
*/
|
375
380
|
const getUsedDependencyMap = (moduleGraph, module, mangle) => {
|
@@ -390,7 +395,15 @@ const getUsedDependencyMap = (moduleGraph, module, mangle) => {
|
|
390
395
|
|
391
396
|
const TYPES = new Set(["webassembly"]);
|
392
397
|
|
398
|
+
/**
|
399
|
+
* @typedef {Object} WebAssemblyGeneratorOptions
|
400
|
+
* @property {boolean} [mangleImports] mangle imports
|
401
|
+
*/
|
402
|
+
|
393
403
|
class WebAssemblyGenerator extends Generator {
|
404
|
+
/**
|
405
|
+
* @param {WebAssemblyGeneratorOptions} options options
|
406
|
+
*/
|
394
407
|
constructor(options) {
|
395
408
|
super();
|
396
409
|
this.options = options;
|
@@ -423,7 +436,7 @@ class WebAssemblyGenerator extends Generator {
|
|
423
436
|
* @returns {Source} generated code
|
424
437
|
*/
|
425
438
|
generate(module, { moduleGraph, runtime }) {
|
426
|
-
const bin = module.originalSource().source();
|
439
|
+
const bin = /** @type {Source} */ (module.originalSource()).source();
|
427
440
|
|
428
441
|
const initFuncId = t.identifier("");
|
429
442
|
|
@@ -55,7 +55,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
55
55
|
runtimeRequirements,
|
56
56
|
runtime
|
57
57
|
} = generateContext;
|
58
|
-
/** @type {InitFragment[]} */
|
58
|
+
/** @type {InitFragment<InitFragment<string>>[]} */
|
59
59
|
const initFragments = [];
|
60
60
|
|
61
61
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
@@ -14,6 +14,7 @@ const memoize = require("../util/memoize");
|
|
14
14
|
const WebAssemblyInInitialChunkError = require("./WebAssemblyInInitialChunkError");
|
15
15
|
|
16
16
|
/** @typedef {import("webpack-sources").Source} Source */
|
17
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
17
18
|
/** @typedef {import("../Compiler")} Compiler */
|
18
19
|
/** @typedef {import("../Module")} Module */
|
19
20
|
/** @typedef {import("../ModuleTemplate")} ModuleTemplate */
|
@@ -29,7 +30,15 @@ const getWebAssemblyParser = memoize(() => require("./WebAssemblyParser"));
|
|
29
30
|
|
30
31
|
const PLUGIN_NAME = "WebAssemblyModulesPlugin";
|
31
32
|
|
33
|
+
/**
|
34
|
+
* @typedef {Object} WebAssemblyModulesPluginOptions
|
35
|
+
* @property {boolean} [mangleImports] mangle imports
|
36
|
+
*/
|
37
|
+
|
32
38
|
class WebAssemblyModulesPlugin {
|
39
|
+
/**
|
40
|
+
* @param {WebAssemblyModulesPluginOptions} options options
|
41
|
+
*/
|
33
42
|
constructor(options) {
|
34
43
|
this.options = options;
|
35
44
|
}
|
@@ -83,7 +92,9 @@ class WebAssemblyModulesPlugin {
|
|
83
92
|
compareModulesByIdentifier
|
84
93
|
)) {
|
85
94
|
if (module.type === WEBASSEMBLY_MODULE_TYPE_SYNC) {
|
86
|
-
const filenameTemplate =
|
95
|
+
const filenameTemplate =
|
96
|
+
/** @type {NonNullable<OutputOptions["webassemblyModuleFilename"]>} */
|
97
|
+
(outputOptions.webassemblyModuleFilename);
|
87
98
|
|
88
99
|
result.push({
|
89
100
|
render: () =>
|
@@ -61,6 +61,9 @@ const decoderOpts = {
|
|
61
61
|
};
|
62
62
|
|
63
63
|
class WebAssemblyParser extends Parser {
|
64
|
+
/**
|
65
|
+
* @param {{}=} options parser options
|
66
|
+
*/
|
64
67
|
constructor(options) {
|
65
68
|
super();
|
66
69
|
this.hooks = Object.freeze({});
|
@@ -88,10 +91,12 @@ class WebAssemblyParser extends Parser {
|
|
88
91
|
const moduleContext = moduleContextFromModuleAST(module);
|
89
92
|
|
90
93
|
// extract imports and exports
|
94
|
+
/** @type {string[]} */
|
91
95
|
const exports = [];
|
92
96
|
let jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports =
|
93
97
|
undefined);
|
94
98
|
|
99
|
+
/** @type {TODO[]} */
|
95
100
|
const importedGlobals = [];
|
96
101
|
t.traverse(module, {
|
97
102
|
ModuleExport({ node }) {
|
@@ -157,12 +162,14 @@ class WebAssemblyParser extends Parser {
|
|
157
162
|
} else if (t.isTable(node.descr) === true) {
|
158
163
|
onlyDirectImport = "Table";
|
159
164
|
} else if (t.isFuncImportDescr(node.descr) === true) {
|
160
|
-
const incompatibleType = getJsIncompatibleType(
|
165
|
+
const incompatibleType = getJsIncompatibleType(
|
166
|
+
/** @type {t.Signature} */ (node.descr.signature)
|
167
|
+
);
|
161
168
|
if (incompatibleType) {
|
162
169
|
onlyDirectImport = `Non-JS-compatible Func Signature (${incompatibleType})`;
|
163
170
|
}
|
164
171
|
} else if (t.isGlobalType(node.descr) === true) {
|
165
|
-
const type = node.descr.valtype;
|
172
|
+
const type = /** @type {string} */ (node.descr.valtype);
|
166
173
|
if (!JS_COMPAT_TYPES.has(type)) {
|
167
174
|
onlyDirectImport = `Non-JS-compatible Global Type (${type})`;
|
168
175
|
}
|
@@ -22,7 +22,7 @@ const MANGLED_MODULE = "a";
|
|
22
22
|
/**
|
23
23
|
* @param {ModuleGraph} moduleGraph the module graph
|
24
24
|
* @param {Module} module the module
|
25
|
-
* @param {boolean} mangle mangle module and export names
|
25
|
+
* @param {boolean | undefined} mangle mangle module and export names
|
26
26
|
* @returns {UsedWasmDependency[]} used dependencies and (mangled) name
|
27
27
|
*/
|
28
28
|
const getUsedDependencies = (moduleGraph, module, mangle) => {
|
@@ -9,6 +9,7 @@ const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
|
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
10
|
const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
12
13
|
/** @typedef {import("../Compiler")} Compiler */
|
13
14
|
|
14
15
|
class FetchCompileAsyncWasmPlugin {
|
@@ -22,6 +23,10 @@ class FetchCompileAsyncWasmPlugin {
|
|
22
23
|
"FetchCompileAsyncWasmPlugin",
|
23
24
|
compilation => {
|
24
25
|
const globalWasmLoading = compilation.outputOptions.wasmLoading;
|
26
|
+
/**
|
27
|
+
* @param {Chunk} chunk chunk
|
28
|
+
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
29
|
+
*/
|
25
30
|
const isEnabledForChunk = chunk => {
|
26
31
|
const options = chunk.getEntryOptions();
|
27
32
|
const wasmLoading =
|
@@ -30,6 +35,10 @@ class FetchCompileAsyncWasmPlugin {
|
|
30
35
|
: globalWasmLoading;
|
31
36
|
return wasmLoading === "fetch";
|
32
37
|
};
|
38
|
+
/**
|
39
|
+
* @param {string} path path to the wasm file
|
40
|
+
* @returns {string} code to load the wasm file
|
41
|
+
*/
|
33
42
|
const generateLoadBinaryCode = path =>
|
34
43
|
`fetch(${RuntimeGlobals.publicPath} + ${path})`;
|
35
44
|
|
@@ -9,15 +9,24 @@ const { WEBASSEMBLY_MODULE_TYPE_SYNC } = require("../ModuleTypeConstants");
|
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
10
|
const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
12
13
|
/** @typedef {import("../Compiler")} Compiler */
|
13
14
|
|
14
15
|
// TODO webpack 6 remove
|
15
16
|
|
16
17
|
const PLUGIN_NAME = "FetchCompileWasmPlugin";
|
17
18
|
|
19
|
+
/**
|
20
|
+
* @typedef {Object} FetchCompileWasmPluginOptions
|
21
|
+
* @property {boolean} [mangleImports] mangle imports
|
22
|
+
*/
|
23
|
+
|
18
24
|
class FetchCompileWasmPlugin {
|
19
|
-
|
20
|
-
|
25
|
+
/**
|
26
|
+
* @param {FetchCompileWasmPluginOptions} [options] options
|
27
|
+
*/
|
28
|
+
constructor(options = {}) {
|
29
|
+
this.options = options;
|
21
30
|
}
|
22
31
|
|
23
32
|
/**
|
@@ -28,6 +37,10 @@ class FetchCompileWasmPlugin {
|
|
28
37
|
apply(compiler) {
|
29
38
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
30
39
|
const globalWasmLoading = compilation.outputOptions.wasmLoading;
|
40
|
+
/**
|
41
|
+
* @param {Chunk} chunk chunk
|
42
|
+
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
43
|
+
*/
|
31
44
|
const isEnabledForChunk = chunk => {
|
32
45
|
const options = chunk.getEntryOptions();
|
33
46
|
const wasmLoading =
|
@@ -36,6 +49,10 @@ class FetchCompileWasmPlugin {
|
|
36
49
|
: globalWasmLoading;
|
37
50
|
return wasmLoading === "fetch";
|
38
51
|
};
|
52
|
+
/**
|
53
|
+
* @param {string} path path to the wasm file
|
54
|
+
* @returns {string} code to load the wasm file
|
55
|
+
*/
|
39
56
|
const generateLoadBinaryCode = path =>
|
40
57
|
`fetch(${RuntimeGlobals.publicPath} + ${path})`;
|
41
58
|
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
9
|
const JsonpChunkLoadingRuntimeModule = require("./JsonpChunkLoadingRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
12
|
/** @typedef {import("../Compiler")} Compiler */
|
12
13
|
|
13
14
|
class JsonpChunkLoadingPlugin {
|
@@ -21,6 +22,10 @@ class JsonpChunkLoadingPlugin {
|
|
21
22
|
"JsonpChunkLoadingPlugin",
|
22
23
|
compilation => {
|
23
24
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
25
|
+
/**
|
26
|
+
* @param {Chunk} chunk chunk
|
27
|
+
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
28
|
+
*/
|
24
29
|
const isEnabledForChunk = chunk => {
|
25
30
|
const options = chunk.getEntryOptions();
|
26
31
|
const chunkLoading =
|
@@ -30,6 +35,10 @@ class JsonpChunkLoadingPlugin {
|
|
30
35
|
return chunkLoading === "jsonp";
|
31
36
|
};
|
32
37
|
const onceForChunkSet = new WeakSet();
|
38
|
+
/**
|
39
|
+
* @param {Chunk} chunk chunk
|
40
|
+
* @param {Set<string>} set runtime requirements
|
41
|
+
*/
|
33
42
|
const handler = (chunk, set) => {
|
34
43
|
if (onceForChunkSet.has(chunk)) return;
|
35
44
|
onceForChunkSet.add(chunk);
|
@@ -46,6 +46,9 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
46
46
|
return hooks;
|
47
47
|
}
|
48
48
|
|
49
|
+
/**
|
50
|
+
* @param {Set<string>} runtimeRequirements runtime requirements
|
51
|
+
*/
|
49
52
|
constructor(runtimeRequirements) {
|
50
53
|
super("jsonp chunk loading", RuntimeModule.STAGE_ATTACH);
|
51
54
|
this._runtimeRequirements = runtimeRequirements;
|
@@ -426,7 +429,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
426
429
|
"}"
|
427
430
|
]),
|
428
431
|
"}",
|
429
|
-
|
432
|
+
`if(runtime) var result = runtime(${RuntimeGlobals.require});`
|
430
433
|
]),
|
431
434
|
"}",
|
432
435
|
"if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);",
|
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
|
10
10
|
const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
12
13
|
/** @typedef {import("../Compiler")} Compiler */
|
13
14
|
|
14
15
|
class ImportScriptsChunkLoadingPlugin {
|
@@ -26,6 +27,10 @@ class ImportScriptsChunkLoadingPlugin {
|
|
26
27
|
"ImportScriptsChunkLoadingPlugin",
|
27
28
|
compilation => {
|
28
29
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
30
|
+
/**
|
31
|
+
* @param {Chunk} chunk chunk
|
32
|
+
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
33
|
+
*/
|
29
34
|
const isEnabledForChunk = chunk => {
|
30
35
|
const options = chunk.getEntryOptions();
|
31
36
|
const chunkLoading =
|
@@ -35,6 +40,10 @@ class ImportScriptsChunkLoadingPlugin {
|
|
35
40
|
return chunkLoading === "import-scripts";
|
36
41
|
};
|
37
42
|
const onceForChunkSet = new WeakSet();
|
43
|
+
/**
|
44
|
+
* @param {Chunk} chunk chunk
|
45
|
+
* @param {Set<string>} set runtime requirements
|
46
|
+
*/
|
38
47
|
const handler = (chunk, set) => {
|
39
48
|
if (onceForChunkSet.has(chunk)) return;
|
40
49
|
onceForChunkSet.add(chunk);
|