Skip to content

Commit 9156be9

Browse files
committed
rename and move BaseWasmMainTemplatePlugin
align usage with other plugins
1 parent 82a71be commit 9156be9

5 files changed

Lines changed: 24 additions & 152 deletions

‎lib/node/ReadFileCompileWasmMainTemplatePlugin.js‎

Lines changed: 0 additions & 113 deletions
This file was deleted.

‎lib/node/ReadFileCompileWasmTemplatePlugin.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const BaseWasmMainTemplatePlugin = require("../BaseWasmMainTemplatePlugin");
7+
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
88

99
class ReadFileCompileWasmTemplatePlugin {
1010
apply(compiler) {
@@ -32,9 +32,8 @@ class ReadFileCompileWasmTemplatePlugin {
3232
});
3333
`;
3434

35-
new BaseWasmMainTemplatePlugin().apply(
36-
compilation.mainTemplate,
37-
generateLoadBinaryCode
35+
new WasmMainTemplatePlugin(generateLoadBinaryCode).apply(
36+
compilation.mainTemplate
3837
);
3938
}
4039
);
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
"use strict";
66

7-
const Template = require("./Template");
8-
const WebAssemblyImportDependency = require("./dependencies/WebAssemblyImportDependency");
7+
const Template = require("../Template");
8+
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
99

1010
// Get all wasm modules
1111
function getAllWasmModules(chunk) {
@@ -76,10 +76,13 @@ function generateImportObject(module) {
7676
return JSON.stringify(module.id) + ": {" + importsCode.join(",") + "\n},";
7777
}
7878

79-
class BaseWasmMainTemplatePlugin {
80-
apply(mainTemplate, generateLoadBinaryCode) {
79+
class WasmMainTemplatePlugin {
80+
constructor(generateLoadBinaryCode) {
81+
this.generateLoadBinaryCode = generateLoadBinaryCode;
82+
}
83+
apply(mainTemplate) {
8184
mainTemplate.hooks.localVars.tap(
82-
"BaseWasmMainTemplatePlugin",
85+
"WasmMainTemplatePlugin",
8386
(source, chunk) => {
8487
if (!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly")))
8588
return source;
@@ -92,7 +95,7 @@ class BaseWasmMainTemplatePlugin {
9295
}
9396
);
9497
mainTemplate.hooks.requireEnsure.tap(
95-
"BaseWasmMainTemplatePlugin",
98+
"WasmMainTemplatePlugin",
9699
(source, chunk, hash) => {
97100
const webassemblyModuleFilename =
98101
mainTemplate.outputOptions.webassemblyModuleFilename;
@@ -150,7 +153,7 @@ class BaseWasmMainTemplatePlugin {
150153
'// a Promise means "currently loading" or "already loaded".',
151154
Template.indent([
152155
`var importObject = importObjects[wasmModuleId]`,
153-
`var req = ${generateLoadBinaryCode(wasmModuleSrcPath)}`,
156+
`var req = ${this.generateLoadBinaryCode(wasmModuleSrcPath)}`,
154157
"if(typeof WebAssembly.instantiateStreaming === 'function') {",
155158
Template.indent([
156159
"promises.push(WebAssembly.instantiateStreaming(req, importObject)",
@@ -186,7 +189,7 @@ class BaseWasmMainTemplatePlugin {
186189
}
187190
);
188191
mainTemplate.hooks.requireExtensions.tap(
189-
"BaseWasmMainTemplatePlugin",
192+
"WasmMainTemplatePlugin",
190193
(source, chunk) => {
191194
if (!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly")))
192195
return source;
@@ -198,12 +201,12 @@ class BaseWasmMainTemplatePlugin {
198201
]);
199202
}
200203
);
201-
mainTemplate.hooks.hash.tap("BaseWasmMainTemplatePlugin", hash => {
202-
hash.update("BaseWasmMainTemplatePlugin");
204+
mainTemplate.hooks.hash.tap("WasmMainTemplatePlugin", hash => {
205+
hash.update("WasmMainTemplatePlugin");
203206
hash.update("1");
204207
hash.update(`${mainTemplate.outputOptions.webassemblyModuleFilename}`);
205208
});
206209
}
207210
}
208211

209-
module.exports = BaseWasmMainTemplatePlugin;
212+
module.exports = WasmMainTemplatePlugin;

‎lib/web/FetchCompileWasmMainTemplatePlugin.js‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎lib/web/FetchCompileWasmTemplatePlugin.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
*/
55
"use strict";
66

7-
const FetchCompileWasmMainTemplatePlugin = require("./FetchCompileWasmMainTemplatePlugin");
7+
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
88

99
class FetchCompileWasmTemplatePlugin {
1010
apply(compiler) {
1111
compiler.hooks.thisCompilation.tap(
1212
"FetchCompileWasmTemplatePlugin",
1313
compilation => {
14-
new FetchCompileWasmMainTemplatePlugin().apply(
15-
compilation.mainTemplate
14+
const mainTemplate = compilation.mainTemplate
15+
const generateLoadBinaryCode = path =>
16+
`fetch(${mainTemplate.requireFn}.p + ${path})`;
17+
18+
new WasmMainTemplatePlugin(generateLoadBinaryCode).apply(
19+
mainTemplate
1620
);
1721
}
1822
);

0 commit comments

Comments
 (0)