.. | ||
public | ||
src | ||
.gitignore | ||
index.html | ||
main.ts | ||
package.json | ||
README.md | ||
tsconfig.json | ||
vite.config.js |
Vite + Automerge
There are three things you need to do to get WASM packaging working with vite:
- Install the top level await plugin
- Install the
vite-plugin-wasm
plugin - Exclude
automerge-wasm
from the optimizer
First, install the packages we need:
yarn add vite-plugin-top-level-await
yarn add vite-plugin-wasm
In vite.config.js
import { defineConfig } from "vite"
import wasm from "vite-plugin-wasm"
import topLevelAwait from "vite-plugin-top-level-await"
export default defineConfig({
plugins: [topLevelAwait(), wasm()],
optimizeDeps: {
// This is necessary because otherwise `vite dev` includes two separate
// versions of the JS wrapper. This causes problems because the JS
// wrapper has a module level variable to track JS side heap
// allocations, initializing this twice causes horrible breakage
exclude: ["@automerge/automerge-wasm"]
}
})
Now start the dev server:
yarn vite
Running the example
yarn install
yarn dev