I'm trying to write hello, world with rust and wasm. Dev server works with
"webpack": "^4.29.3",
"webpack-dev-server": "^3.1.5"
but if update to
"webpack": "^5.90.3",
"webpack-dev-server": "^5.0.2"
Module not found
error occurs after rebuilding wasm.
Steps to reproduce:
git clone https://github.com/levap5/wasm-game-of-life.git
cd wasm-game-of-life
git checkout 90666d3f
wasm-pack build
cd www
npm install
npm run start
| webpack-dev-server will start. There are no errors now.src/lib.rs
wasm-pack build
in wasm-game-of-life
dirThe error occurs after step 10 and http://localhost:8080/
runs old (cached) rust (wasm) code. How to fix this?
I found a solution using wasm-pack-plugin plugin.
package.json:
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.7.0",
// ...
}
webpack.config.js:
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
// ...
plugins: [
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "..") // ".." in my case
}),
// ...
]
// ...
However, the plugin's maintenance is questionable. I immediately came across this issue. After looking at the plugin code, the issue seems easy to fix.