From 1b9860187036d11bcc3dfed3539063cc3753afac Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:54:37 +0100 Subject: [PATCH] Constrain webpack config for `olm.wasm` (#23633) I've been experimenting with loading WebAssembly into EW, for which I need to use webpack's default wasm loader. Currently we're overriding that for *all* files called `*.wasm`, which is too broad. There are currently two `*.wasm` artifacts in EW: `decoderWorker.min.wasm`, and `olm.wasm`. `decoderWorker` has its own rule, so the `*.wasm` rule is only used for `olm.wasm`. So, let's tighten up the test for that rule so that it doesn't catch other innocent `.wasm`s in the cross-fire. --- webpack.config.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 6a3a5bd8a4..a559836b60 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -369,9 +369,14 @@ module.exports = (env, argv) => { ], }, { - test: /\.wasm$/, + // the olm library wants to load its own wasm, rather than have webpack do it. + // We therefore use the `file-loader` to tell webpack to dump the contents to + // a separate file and return the name, and override the default `type` for `.wasm` files + // (which is `webassembly/experimental` under webpack 4) to stop webpack trying to interpret + // the filename as webassembly. (see also https://github.com/webpack/webpack/issues/6725) + test: /olm\.wasm$/, loader: "file-loader", - type: "javascript/auto", // https://github.com/webpack/webpack/issues/6725 + type: "javascript/auto", options: { name: '[name].[hash:7].[ext]', outputPath: '.', @@ -382,7 +387,7 @@ module.exports = (env, argv) => { // We more or less just want it to be clear it's for opus and not something else. test: /encoderWorker\.min\.js$/, loader: "file-loader", - type: "javascript/auto", // https://github.com/webpack/webpack/issues/6725 + type: "javascript/auto", options: { // We deliberately override the name so it makes sense in debugging name: 'opus-encoderWorker.min.[hash:7].[ext]', @@ -422,11 +427,11 @@ module.exports = (env, argv) => { }, }, { - // This is from the same place as the encoderWorker above, but only needed - // for Safari support. + // Same deal as olm.wasm: the decoderWorker wants to load the wasm artifact + // itself. test: /decoderWorker\.min\.wasm$/, loader: "file-loader", - type: "javascript/auto", // https://github.com/webpack/webpack/issues/6725 + type: "javascript/auto", options: { // We deliberately don't change the name because the decoderWorker has this // hardcoded. This is here to avoid the default wasm rule from adding a hash. @@ -652,6 +657,7 @@ module.exports = (env, argv) => { // chunks even after the app is redeployed. filename: "bundles/[hash]/[name].js", chunkFilename: "bundles/[hash]/[name].js", + webassemblyModuleFilename: "bundles/[hash]/[modulehash].wasm", }, // configuration for the webpack-dev-server