web: Simplify .wasm loading

Use wasm-bindgen's built-in loader instead of relying on Webpack.

This allows to no longer declare .wasm files as resource assets in
each webpack.config.js.

Also the bundled JS is a bit smaller (e.g. demo is now ~88KB vs.
~90KB before).
This commit is contained in:
relrelb 2021-07-24 00:36:36 +03:00 committed by Mike Welsh
parent 6b91239e28
commit 66bfff7687
4 changed files with 1 additions and 23 deletions

View File

@ -20,13 +20,7 @@ async function fetchRuffle(): Promise<typeof Ruffle> {
// libraries, if needed. // libraries, if needed.
setPolyfillsOnLoad(); setPolyfillsOnLoad();
// wasm files are set to be resource assets, await init();
// so this import will resolve to the URL of the wasm file.
const ruffleWasm = await import(
/* webpackMode: "eager" */
"../pkg/ruffle_web_bg.wasm"
);
await init(ruffleWasm.default);
return Ruffle; return Ruffle;
} }

View File

@ -22,10 +22,6 @@ module.exports = (_env, _argv) => {
test: /\.css$/i, test: /\.css$/i,
use: ["style-loader", "css-loader"], use: ["style-loader", "css-loader"],
}, },
{
test: /\.wasm$/i,
type: "asset/resource",
},
], ],
}, },
devtool: "source-map", devtool: "source-map",

View File

@ -62,10 +62,6 @@ module.exports = (env, _argv) => {
test: /\.ts$/i, test: /\.ts$/i,
use: "ts-loader", use: "ts-loader",
}, },
{
test: /\.wasm$/i,
type: "asset/resource",
},
], ],
}, },
resolve: { resolve: {

View File

@ -17,14 +17,6 @@ module.exports = (_env, _argv) => {
chunkFilename: "core.ruffle.[contenthash].js", chunkFilename: "core.ruffle.[contenthash].js",
clean: true, clean: true,
}, },
module: {
rules: [
{
test: /\.wasm$/i,
type: "asset/resource",
},
],
},
devtool: "source-map", devtool: "source-map",
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({