JSPM

  • Created
  • Published
  • Downloads 140
  • Score
    100M100P100Q91131F
  • License MIT

wasm-pack plugin for Vite

Package Exports

  • vite-plugin-rsw

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vite-plugin-rsw) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

vite-plugin-rsw

wasm-pack plugin for Vite

npm npm downloads vite version chat

awesome-rsw Rust WebAssembly

Pre-installed

Article

Features

  • startup optimization
  • enable debug mode: DEBUG=rsw yarn dev
  • friendly error message: browser and terminal
  • automatically generate template when crate does not exist
  • multiple rust crate
    • compile
    • hot-update

rsw run rsw error rsw debug

rsw new
rsw error wasm-pack
rsw error outdir

Quick Start

create-xc-app: create a project in seconds!

template: wasm-vue3 and wasm-react

# With NPM
npm init xc-app

# With Yarn:
yarn create xc-app

Getting Started

Step1

Install and configure rsw.

# install rsw
npm i -D vite-plugin-rsw

# or
yarn add -D vite-plugin-rsw
// vite.config.ts
import { defineConfig } from 'vite';
import ViteRsw from 'vite-plugin-rsw';

export default defineConfig({
  plugins: [
    ViteRsw({
      crates: [
        '@rsw/hey',
        'rsw-test',
        // https://github.com/lencx/vite-plugin-rsw/issues/8#issuecomment-820281861
        // outDir: use `path.resolve` or relative path.
        { name: '@rsw/hello', outDir: 'custom/path' },
      ],
    }),
  ],
});

Step2

Use exported Rust things from JavaScript with ECMAScript modules!

import init, { greet } from '@rsw/hey';

// 1. `WebAssembly.Instance` initialization
init();

// 2. Make sure this method is executed after `init()` is called
greet('World!');

Plugin Options

  • cli: specified package manager npm or pnpm, default npm.
  • root: rust crate root path. default project root path.
  • unLinks: string[] - (npm unlink) uninstalls a package.
  • crates: Item[ ] - (npm link) package name, support npm organization.
    • Item as string - '@rsw/hello'
    • Item as RswCrateOptions - { name: '@rsw/hello', outDir: 'custom/path' }

⚠️ Note: Before performing the vite build, at least once vite dev, generate wasm package (rust-crate/pkg). In the project, wasm package is installed by vite-plugin-rsw in the form of npm link, otherwise it will error Can not find module 'rust-crate' or its corresponding type declarations.

Remote Deployment

Install

Install lencx/rsw-node globally, you can use the rsw command.

npm i -g rsw-node
rsw help

Example

npm install -D rsw-node
"scripts": {
  "rsw:deploy": "rsw && npm run build"
}

rsw deploy

Video

Examples

Credits

Backers

Thank you to all our backers! 🙏

微信

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

wasm-wechat-qrcode fzj-qrcode

License

MIT License © 2021 lencx