rsw = rs(rust) → w(wasm) - 基于 wasm-pack 实现的一个命令行工具,当本地文件变更时自动构建。
English | 简体中文
# 在 Rust 环境下安装到全局
cargo install rsw# 查看帮助
rsw -h
# rsw.toml - 初始化配置
rsw init
# 生成一个 wasm 项目
rsw new <name>
# 开发模式
rsw watch
# 生产构建
rsw build
# 清除 link 及 build 产物
rsw clean- [rsw demo] learn-wasm - 🎲 Learning WebAssembly
- vite-plugin-rsw - 🦀 wasm-pack plugin for Vite
- create-mpl - ⚡️ Create a project in seconds!
# @see: https://github.com/env-logger-rs/env_logger
# RUST_LOG=rsw=<info|trace|debug|error|warn> rsw <watch|build|new>
# 1. info
RUST_LOG=rsw=info rsw <SUBCOMMAND>
# 2. all: info, trace, debug, error, warn
RUST_LOG=rsw rsw <SUBCOMMAND>定义要忽略的文件/路径,类似于 .gitignore。
例如:
# .watchignore
*.js
a/b/**/*.txt
!a/b/**/main.txt配置文件
在项目根路径下创建 rsw.toml,配置 rust crate 参数,然后执行 rsw watch 或者 rsw build。
name- 配置文件名称(无意义,可选)version- 配置文件版本(无意义,可选)interval- 开发模式rsw watch下,文件变更触发wasm-pack build的时间间隔,默认50毫秒cli-npm|yarn|pnpm,默认是npm。使用指定的cli执行link,例如npm link[new]- 使用wasm-pack new快速生成一个rust crate, 或者使用自定义模板rsw.toml -> [new] -> usingusing-wasm-pack|rsw|user, 默认是wasm-packwasm-pack-rsw new <name> --template <template> --mode <normal|noinstall|force>,了解更多 wasm-pack new 文档rsw-rsw new <name>, 使用内置模板user-rsw new <name>, 如果未设置dir,则使用wasm-pack new <name>初始化项目
dir- 如果using = "user"则复制此目录下的所有文件初始化项目,using = "wasm-pack"或using = "rsw"时,则忽略这个字段
[[crates]]- 是一个数组,支持多个rust crate配置name- npm 包名,支持组织,例如@rsw/fooroot- 此rust crate在项目根路径下的相对路径,默认.link-true|false,默认为false,此rust crate构建后是否执行link命令,与cli配合使用target-bundler|nodejs|web|no-modules, 默认webscope- npm 组织out-dir- npm 包输出路径,默认pkg[crates.watch]- 开发模式下的配置run- 是否执行,默认为trueprofile-dev|profiling,默认dev
[crates.build]- 生产构建下的配置run- 是否执行,默认为trueprofile-release|profiling,默认release
注意:[[crates]] 中 name 是必须的,其他字段均为可选。
rsw watch- 临时目录
- rsw.info -
watch模式下相关信息[RSW::OK][RSW::ERR][RSW::NAME][RSW::PATH][RSW::BUILD]
- rsw.err -
wasm-pack build失败信息 - rsw.crates -
rsw.toml中的所有包信息
# rsw.toml
name = "rsw"
version = "0.1.0"
#! time interval for file changes to trigger wasm-pack build, default `50` milliseconds
interval = 50
#! link
#! npm link @see https://docs.npmjs.com/cli/v8/commands/npm-link
#! yarn link @see https://classic.yarnpkg.com/en/docs/cli/link
#! pnpm link @see https://pnpm.io/cli/link
#! The link command will only be executed if `[[crates]] link = true`
#! cli: `npm` | `yarn` | `pnpm`, default is `npm`
cli = "npm"
#! ---------------------------
#! rsw new <name>
[new]
#! @see https://rustwasm.github.io/docs/wasm-pack/commands/new.html
#! using: `wasm-pack` | `rsw` | `user`, default is `wasm-pack`
#! 1. wasm-pack: `rsw new <name> --template <template> --mode <normal|noinstall|force>`
#! 2. rsw: `rsw new <name>`, built-in templates
#! 3. user: `rsw new <name>`, if `dir` is not configured, use `wasm-pack new <name>` to initialize the project
using = "wasm-pack"
#! this field needs to be configured when `using = "user"`
#! `using = "wasm-pack"` or `using = "rsw"`, this field will be ignored
#! copy all files in this directory
dir = "my-template"
#! ################# NPM Package #################
#! When there is only `name`, other fields will use the default configuration
#! 📦 -------- package: rsw-hello --------
[[crates]]
#! npm package name (path: $ROOT/rsw-hello)
name = "rsw-hello"
#! run `npm link`: `true` | `false`, default is `false`
link = false
#! 📦 -------- package: @rsw/utils --------
[[crates]]
#! npm package name (path: $ROOT/utils)
name = "utils"
# #! scope: npm org
scope = "rsw"
#! run `npm link`: `true` | `false`, default is `false`
link = false
#! 📦 -------- package: @rsw/hello --------
[[crates]]
#! npm package name (path: $ROOT/@rsw/hello)
name = "@rsw/hello"
#! default is `.`
root = "."
#! default is `pkg`
out-dir = "pkg"
#! target: bundler | nodejs | web | no-modules, default is `web`
target = "web"
#! run `npm link`: `true` | `false`, default is `false`
link = false
#! rsw watch
[crates.watch]
#! default is `true`
run = true
#! profile: `dev` | `profiling`, default is `dev`
profile = "dev"
#! rsw build
[crates.build]
#! default is `true`
run = true
#! profile: `release` | `profiling`, default is `release`
profile = "release"MIT License © 2022 lencx
