use vite-plugin-wasm-pack

This commit is contained in:
Ilion Beyst 2021-12-23 19:25:56 +01:00
parent c26f72890f
commit d0af8d3bbf
4 changed files with 11 additions and 9 deletions

View file

@ -5,10 +5,12 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"wasm": "wasm-pack build ./planetwars-rs --target web",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {
"@originjs/vite-plugin-commonjs": "^1.0.1",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"@tsconfig/svelte": "^2.0.1",
"rollup-plugin-polyfill-node": "^0.8.0",
@ -17,13 +19,13 @@
"svelte-preprocess": "^4.9.8",
"tslib": "^2.3.1",
"typescript": "^4.4.4",
"vite": "^2.7.2"
"vite": "^2.7.2",
"vite-plugin-wasm-pack": "^0.1.9"
},
"dependencies": {
"buffer": "^6.0.3",
"extract-svg-path": "^2.1.0",
"load-svg": "^1.0.0",
"planetwars-rs": "file:./planetwars-rs/pkg",
"svg-mesh-3d": "^1.1.0",
"ts-heap": "^1.1.3"
}

View file

@ -14,20 +14,20 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2"
wasm-bindgen = "0.2.63"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true }
console_error_panic_hook = { version = "0.1.6", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.2", optional = true }
wee_alloc = { version = "0.4.5", optional = true }
serde = "1.0.100"
serde_derive = "1.0.100"
serde_json = "1.0"
@ -35,7 +35,7 @@ octoon-math = "0.1.7"
voronoi = "0.1.4"
[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3.13"
[profile.release]
# Tell `rustc` to optimize for small code size.

View file

@ -1,9 +1,7 @@
import App from './App.svelte'
import init_wasm_module from "planetwars-rs";
const wasm_url = new URL("../planetwars-rs/pkg/planetwars_rs_bg.wasm", import.meta.url)
init_wasm_module(wasm_url).then(() => {
init_wasm_module().then(() => {
const app = new App({
target: document.getElementById('app')
})

View file

@ -1,11 +1,13 @@
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
import wasmPack from 'vite-plugin-wasm-pack';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
svelte(),
wasmPack(["./planetwars-rs"]),
viteCommonjs({
transformMixedEsModules: true,
}),