Vite 中文文档 Vite 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • vite

    • 指引
    • 为什么选 Vite
    • 开始
    • 功能
    • 命令行界面
    • 使用插件
    • 依赖预构建
    • 静态资源处理
    • 构建生产版本
    • 部署静态站点
    • 环境变量和模式
    • 服务端渲染
    • 后端集成
    • 与其他工具比较
    • 故障排除
    • 从 v3 迁移
  • API

  • 配置参考

  • vite

  • API

  • 配置参考

vite-plugin-rsw


wasm-pack plugin for Vite


awesome-rsw

rsw version vite version
:--- :---
>= 2.0.0 >= 2.8.0
>= 1.8.0 >= 2.4.0
1.7.0 2.0.0 ~ 2.3.8

Features


HMR
Friendly error message - browser and terminal

Pre-installed


rust
nodejs
wasm-pack
rsw-rs : rsw = rs(rust) → w(wasm) - A command-line tool for automatically rebuilding local changes, based on the wasm-pack implementation.

Usage


Step 1


Install rsw

  1. ``` shell
  2. cargo install rsw
  3. ```

Install vite-plugin-rsw

  1. ``` shell
  2. # With NPM:
  3. npm i -D vite-plugin-rsw

  4. # With Yarn:
  5. yarn add -D vite-plugin-rsw
  6. ```

Step 2


Edit vite.config.ts

  1. ``` js
  2. import { defineConfig } from 'vite';
  3. import { ViteRsw } from 'vite-plugin-rsw';

  4. export default defineConfig({
  5.   plugins: [
  6.     ViteRsw(),
  7.   ],
  8. })
  9. ```

Step 3


Edit package.json

recommend to use concurrently instead of & to run command concurrently, because it can't handle system signal properly, see rwasm/rsw-rs#7


  1. ``` js
  2. "scripts": {
  3. +   "dev": "concurrently \"rsw watch\" \"vite\"",
  4. +   "build": "rsw build && tsc && vite build",
  5. +   "rsw": "rsw"
  6. }
  7. ```

Step 4


rsw.toml options

Initial rsw.toml

  1. ``` shell
  2. # yarn rsw -h
  3. yarn rsw init
  4. ```

Generate rust crate

  1. ``` shell
  2. # rsw.toml
  3. [new]
  4. # using: wasm-pack | rsw | user, default is `wasm-pack`
  5. using = "wasm-pack"
  6. ```

  1. ``` shell
  2. yarn rsw new rsw-hello
  3. ```

Edit rsw.toml

  1. ``` toml
  2. # link type: npm | yarn | pnpm, default is `npm`
  3. cli = "npm"

  4. [[crates]]
  5. name = "rsw-hello"
  6. # <npm|yarn|pnpm> link
  7. # ⚠️ Note: must be set to `true`, default is `false`
  8. link = true
  9. ```

Step 5


Start dev server

  1. ``` shell
  2. # rsw watch & vite
  3. yarn dev
  4. ```

Step 6


Deploy

  1. ``` shell
  2. yarn build
  3. ```

Example


WA+ - 🤩Making a web page more like a desktop application is just the beginning, the possibilities are unlimited, up to your imagination!
Demo - 🎲Learning WebAssembly
Oh My Box - 🔮Development toolbox, and more...

Related


create-mpl - ⚡️Create a project in seconds!

  1. ``` shell
  2. # Quickly initialize a wasm project

  3. # npm 6.x
  4. npm init mpl@latest my-app --type wasm

  5. # npm 7+, extra double-dash is needed:
  6. npm init mpl@latest my-app -- --type wasm
  7. ```

微信


群二维码已过期,关注公众号《浮之静》,发送“进群”,我将拉你进群一起学习。


wasm-wechat-qrcode fzj-qrcode

License


MIT License © 2021 lencx
Last Updated: 2023-05-23 11:11:51