diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-23 19:25:56 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-23 19:25:56 +0100 |
commit | d0af8d3bbff506d4f4caf03750c3b85c69c4f168 (patch) | |
tree | 317b9c2033af3f631dfeb12e064b43d0548e09c8 | |
parent | c26f72890f934d654742328702661f0bd73b7582 (diff) | |
download | planetwars.dev-d0af8d3bbff506d4f4caf03750c3b85c69c4f168.tar.xz planetwars.dev-d0af8d3bbff506d4f4caf03750c3b85c69c4f168.zip |
use vite-plugin-wasm-pack
-rw-r--r-- | web/pw-frontend/package.json | 6 | ||||
-rw-r--r-- | web/pw-frontend/planetwars-rs/Cargo.toml | 8 | ||||
-rw-r--r-- | web/pw-frontend/src/main.ts | 4 | ||||
-rw-r--r-- | web/pw-frontend/vite.config.js | 2 |
4 files changed, 11 insertions, 9 deletions
diff --git a/web/pw-frontend/package.json b/web/pw-frontend/package.json index d1c9c72..2f31ebb 100644 --- a/web/pw-frontend/package.json +++ b/web/pw-frontend/package.json @@ -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" } diff --git a/web/pw-frontend/planetwars-rs/Cargo.toml b/web/pw-frontend/planetwars-rs/Cargo.toml index 31b4d6c..a5dc949 100644 --- a/web/pw-frontend/planetwars-rs/Cargo.toml +++ b/web/pw-frontend/planetwars-rs/Cargo.toml @@ -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. diff --git a/web/pw-frontend/src/main.ts b/web/pw-frontend/src/main.ts index b9ec466..bbe6382 100644 --- a/web/pw-frontend/src/main.ts +++ b/web/pw-frontend/src/main.ts @@ -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') }) diff --git a/web/pw-frontend/vite.config.js b/web/pw-frontend/vite.config.js index bce1f51..e52edb5 100644 --- a/web/pw-frontend/vite.config.js +++ b/web/pw-frontend/vite.config.js @@ -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, }), |