@cfasim-ui/wasm 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/src/vitePlugin.ts +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/wasm",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "description": "WebAssembly integration for cfasim-ui",
6
6
  "license": "Apache-2.0",
@@ -13,10 +13,11 @@
13
13
  "src"
14
14
  ],
15
15
  "exports": {
16
- ".": "./src/index.ts"
16
+ ".": "./src/index.ts",
17
+ "./vite": "./src/vitePlugin.ts"
17
18
  },
18
19
  "dependencies": {
19
- "@cfasim-ui/shared": "0.1.2"
20
+ "@cfasim-ui/shared": "0.1.4"
20
21
  },
21
22
  "peerDependencies": {
22
23
  "vue": "^3.5.0"
@@ -0,0 +1,34 @@
1
+ import { execSync } from "node:child_process";
2
+ import { basename, resolve } from "node:path";
3
+ import type { Plugin } from "vite";
4
+
5
+ interface CfasimWasmOptions {
6
+ /** Path to the Rust model directory (default: "model") */
7
+ model?: string;
8
+ /** Output name used for the wasm module (default: project directory name) */
9
+ name?: string;
10
+ }
11
+
12
+ /**
13
+ * Vite plugin that builds a Rust model to WebAssembly via wasm-pack
14
+ * and outputs it to public/wasm/{name}/.
15
+ */
16
+ export function cfasimWasm(options?: CfasimWasmOptions): Plugin {
17
+ const modelDir = options?.model ?? "model";
18
+
19
+ function build(root: string) {
20
+ const name = options?.name ?? basename(root);
21
+ const outDir = resolve(root, "public", "wasm", name);
22
+ execSync(`wasm-pack build ${modelDir} --target web --out-dir ${outDir}`, {
23
+ cwd: root,
24
+ stdio: "pipe",
25
+ });
26
+ }
27
+
28
+ return {
29
+ name: "cfasim-wasm",
30
+ configResolved(config) {
31
+ build(config.root);
32
+ },
33
+ };
34
+ }