Skip to content

Commit 299270e

Browse files
authored
Move rust-sdk wasm artifact into bundles directory (#28718)
As of matrix-org/matrix-sdk-crypto-wasm#167, the wasm build of matrix-sdk-crypto is actually shipped as a `.wasm` file, rather than base64-ed into Javascript. Our current webpack config then dumps it into the top level of the build directory, which will be a problem on redeployment (specifically, if you try to fetch the wasm artifact for vN after vN+1 has been deployed, you'll get a 404 and sadness). So, instead we use Webpack's experimental support for WASM-as-ES-module, which makes Webpack put the wasm file in the bundle, along with everything else. Fixes: #28632
1 parent 943b817 commit 299270e

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

webpack.config.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ module.exports = (env, argv) => {
120120
return {
121121
...development,
122122

123+
experiments: {
124+
asyncWebAssembly: true,
125+
},
126+
123127
bail: true,
124128

125129
entry: {
@@ -222,6 +226,16 @@ module.exports = (env, argv) => {
222226
// Polyfill needed by sentry
223227
"process/browser": require.resolve("process/browser"),
224228
},
229+
230+
// Enable the custom "wasm-esm" export condition [1] to indicate to
231+
// matrix-sdk-crypto-wasm that we support the ES Module Integration
232+
// Proposal for WebAssembly [2]. The "..." magic value means "the
233+
// default conditions" [3].
234+
//
235+
// [1]: https://nodejs.org/api/packages.html#conditional-exports
236+
// [2]: https://github.com/webassembly/esm-integration
237+
// [3]: https://github.com/webpack/webpack/issues/17692#issuecomment-1866272674.
238+
conditionNames: ["matrix-org:wasm-esm", "..."],
225239
},
226240

227241
// Some of our deps have broken source maps, so we have to ignore warnings or exclude them one-by-one
@@ -681,13 +695,21 @@ module.exports = (env, argv) => {
681695
output: {
682696
path: path.join(__dirname, "webapp"),
683697

684-
// The generated JS (and CSS, from the extraction plugin) are put in a
685-
// unique subdirectory for the build. There will only be one such
686-
// 'bundle' directory in the generated tarball; however, hosting
687-
// servers can collect 'bundles' from multiple versions into one
688-
// directory and symlink it into place - this allows users who loaded
689-
// an older version of the application to continue to access webpack
690-
// chunks even after the app is redeployed.
698+
// There are a lot of assets that need to be kept in sync with each other
699+
// (once a user loads one version of the app, they need to keep being served
700+
// assets for that version).
701+
//
702+
// To deal with this, we try to put as many as possible of the referenced assets
703+
// into a build-specific subdirectory. This includes generated javascript, as well
704+
// as CSS extracted by the MiniCssExtractPlugin (see config above) and WASM modules
705+
// referenced via `import` statements.
706+
//
707+
// Hosting servers can then collect 'bundles' from multiple versions
708+
// into one directory, and continue to serve them even after a new version is deployed.
709+
// This allows users who loaded an older version of the application to continue to
710+
// access assets even after the app is redeployed.
711+
//
712+
// See `scripts/deploy.py` for a script which manages the deployment in this way.
691713
filename: "bundles/[fullhash]/[name].js",
692714
chunkFilename: "bundles/[fullhash]/[name].js",
693715
webassemblyModuleFilename: "bundles/[fullhash]/[modulehash].wasm",

0 commit comments

Comments
 (0)