wasm-pack plugin for Vite
wasm-pack plugin for Vite
rsw version vite version >= 2.0.0>= 2.8.0>= 1.8.0>= 2.4.01.7.02.0.0 ~ 2.3.8
HMRFriendly error message - browser and terminalrsw = rs(rust) → w(wasm) - A command-line tool for automatically rebuilding local changes, based on the wasm-pack implementation.Install rsw
cargo install rswInstall vite-plugin-rsw
# With NPM:
npm i -D vite-plugin-rsw
# With Yarn:
yarn add -D vite-plugin-rswEdit vite.config.ts
import { defineConfig } from 'vite';
import { ViteRsw } from 'vite-plugin-rsw';
export default defineConfig({
plugins: [
ViteRsw(),
],
})Edit package.json
recommend to use
concurrentlyinstead of&to run command concurrently, because it can't handle system signal properly, see https://github.com/rwasm/rsw-rs/issues/7
"scripts": {
+ "dev": "concurrently \"rsw watch\" \"vite\"",
+ "build": "rsw build && tsc && vite build",
+ "rsw": "rsw"
}Initial rsw.toml
# yarn rsw -h
yarn rsw initGenerate rust crate
# rsw.toml
[new]
# using: wasm-pack | rsw | user, default is `wasm-pack`
using = "wasm-pack"yarn rsw new rsw-helloEdit rsw.toml
# link type: npm | yarn | pnpm, default is `npm`
cli = "npm"
[[crates]]
name = "rsw-hello"
# link
# ⚠️ Note: must be set to `true`, default is `false`
link = trueStart dev server
# rsw watch & vite
yarn devDeploy
yarn buildcreate-mpl - ⚡️ Create a project in seconds!
# Quickly initialize a wasm project
# npm 6.x
npm init mpl@latest my-app --type wasm
# npm 7+, extra double-dash is needed:
npm init mpl@latest my-app -- --type wasm群二维码已过期,关注公众号《浮之静》,发送“进群”,我将拉你进群一起学习。
MIT License © 2021 lencx
No open issues yet, or sync has not completed.