• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🦀 Vite plugin for rust wasm-pack

vite + wasm pic

🦀 Vite plugin for rust wasm-pack, it's simple.

npm npm npm

Quick start

Make sure wasm-pack installed correctly.

Clone this repo or download the zip file, extract the example folder.

example
  |
  |-- my-crate       # rust project folder, there is a Cargo.toml in it
  |-- src            # front end source code
  |   |-- index.ts   # entry point
  |-- index.html     # html entry
  |-- vite.config.ts # vite config file
  |__ package.json   # npm config file

Install npm develop dependencies, in example folder run:

yarn install
# or
# npm install

After that you can build rust project to WebAassembly by using wasm-pack.

wasm-pack build ./my-crate --target web

Now the my-crate module is ready, start vite dev server.

yarn dev
or
#npm run dev

Done, if below is showing.

  vite v2.6.5 dev server running at:

  > Local: http://localhost:3000/

  ready in 169ms.

Install manually

yarn add vite vite-plugin-wasm-pack -D
# or
# npm i vite vite-plugin-wasm-pack vite -D

Usage

Add this plugin to vite.config.ts

import { defineConfig } from 'vite';
import wasmPack from 'vite-plugin-wasm-pack';

export default defineConfig({
  // pass your local crate path to the plugin
  plugins: [wasmPack('./my-crate')]
});

Add script to package.json

"scripts": {
  "dev": "vite",
  "build": "vite build"
}

Don't forget to build your wasm-pack crate first!

wasm-pack build ./my-crate --target web

Tips: you can add a wasm script to package.json like this:

"scripts": {
    "wasm": "wasm-pack build ./my-crate --target web",
    "dev": "yarn wasm && vite",
    "build": "vite build"
}

Then, run:

yarn dev

This will start dev server, and install my-crate that you built earlier.

Use wasm-pack package installed via npm

If you want use a package from npm that built with wasm-pack, like this one test-npm-crate

you have to pass the package name to the second param of our plugin.

wasmPack(['./my-local-crate'],['test-npm-crate'])

full example is in ./npm-crate-example folder.

notice, we only support package build with --target web for now , if a package you use is built without --target web, you should rebuild it.

like this example [Photon-vite] [source]

Cache Problem

I'm not sure if anybody have met the problem that after modified your package, your package don't update.

That's becasue vite pre bundling your package, you can follow vite guide to solve the problem.

If you met the problem , or any problems. feel free to create an issue, let me see if I can do something to help you, thanks.

Examples

License

MIT, see the license file

More Repositories

1

learn-neovim-lua

Neovim 配置实战:从 0 到 1 打造自己的 IDE
Lua
1,075
star
2

vite-plugin-cesium

⚡ Vite plugin for Cesium
TypeScript
171
star
3

InsisVim

🗃 An out-of-the-box Neovim IDE solution that setup development environment in an incredibly simple way.
Lua
88
star
4

create-cesium

🌏 Create blazing fast Cesium apps with no configuration.
JavaScript
45
star
5

as2ts

Convert ActionScript 3 to TypeScript on web
JavaScript
42
star
6

narrowing

🤖 TypeScript tiny narrowing helpers you better use.
TypeScript
29
star
7

Stage3D.js

Stage3d API on top of WebGL
TypeScript
21
star
8

coding-blog

程序员的私房极简博客系统
CSS
20
star
9

zimuzu

美剧资源
11
star
10

as3DataStructure

常见数据结构
ActionScript
10
star
11

ts-lerna-repo

lerna+ typescript + babel + rollup 项目结构
JavaScript
9
star
12

mini-shed

迷你屋 是一个开放,模块化,数据驱动,前端友好的小游戏框架 🎮(实验中)
TypeScript
8
star
13

ObjectSocket

flash与nodejs通过socket互相发送object
TypeScript
3
star
14

photon-vite

photon with vitejs demo
TypeScript
3
star
15

vite-wasm-game-of-life

An example of vite-plugin-wasm-pack
Rust
3
star
16

onePageHTML

《HTML and CSS Design and Build Websites》笔记
2
star
17

my-react-starter-2021

React 脚手架 Next.js + Chakra-ui + Recoil + axios-hooks
TypeScript
2
star
18

PDF2Mag

一键Pdf文档转Flash电子杂志
JavaScript
2
star
19

ogl-typescript-starter

ogl-typescript starter with code minifier and livereload dev server.
TypeScript
2
star
20

nshen.github.com

test new blog
HTML
2
star
21

tsup-tsm-demo

a typescript tsm package
TypeScript
1
star
22

next-palywright-action-demo

JavaScript
1
star
23

test-npm-crate

vite-plugin-wasm-pack test crate
Rust
1
star
24

dotfiles

Shell
1
star
25

lens-server

TypeScript
1
star
26

nshen

1
star
27

ts-project-starter

TypeScript Project Starter 2019
JavaScript
1
star
28

as3DesignPattern

学习设计模式用。。待整理
ActionScript
1
star
29

shed-ecs

Entity-Component-System for minigame
TypeScript
1
star
30

ts-jest-starter

JavaScript
1
star
31

cesium-rollup

cesium rollup starter
JavaScript
1
star