Git Product home page Git Product logo

plugin-repack's Introduction

Repack 1.1

Yarn plugin for easy integration of rust wasm into a web or nodejs project

Installation

  1. Install rust nightly toolchain and cargo
  2. Setup rust for wasm32-unknown-unknown target
  3. Install yarn (v3/4)
  4. Install plugin in the project with cargo workspaces + yarn workspaces
yarn plugin import https://raw.githubusercontent.com/LIMPIX31/plugin-repack/master/yarn-plugin/bundles/@yarnpkg/plugin-repack.js
yarn repack install

Usage

Create wasm crate

cargo new --lib hello-world

...and add target

[lib]
crate-type = ["cdylib"]

[repack]
target = "web" # or "nodejs"

...and add crate to cargo workspaces

[workspace]
members = [
  "hello-world"
]

Add crate to yarn workspace dependencies and build

{
 "name": "my-project",
 "version": "1.0.0",
 "main": "src/index.ts",
 "dependencies": {
   "@crate/hello-world": "crate:*"
 }
}

...then make the initial build

yarn

Rebuild crates

# Try rebuild only hello-world
yarn repack rebuild hello-world
# Try rebuild all crates
yarn repack rebuild
# Try rebuild hello-world crate for release
yarn repack rebuild --release hello-world

Import your crate

import { hello_world } from '@crate/hello-world'

Example

You can find examples in examples branch

git checkout examples

Known issues

When using vite, you need to exclude crate

export default defineConfig({
  plugins: [react()],
  build: {
    target: 'esnext'
  },
  optimizeDeps: {
    exclude: ['@crate/my-crate']
  },
})

Misc

@crate scope

...is required. It is needed to restrict your dependencies semantically, so that you can understand that you are importing a crate and not something else

plugin-repack's People

Contributors

limpix31 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

plugin-repack's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.