From 2b29ecf8eee3c84ff91a77e0f8d73eb4489531e4 Mon Sep 17 00:00:00 2001 From: Shnoorg Date: Mon, 2 Sep 2024 20:03:50 -0700 Subject: [PATCH 1/3] adds support for custom wasm-pack --out-names --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7277875..f88b3ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,10 +23,12 @@ import { PluginOption } from 'vite'; * * @param crates local crates paths, if you only use crates from npm, leave an empty array here. * @param moduleCrates crates names from npm + * @param outName use the wasm-pack --out-name for the published package */ function vitePluginWasmPack( crates: string[] | string, - moduleCrates?: string[] | string + moduleCrates?: string[] | string, + outName?: string, ): PluginOption { const prefix = '@vite-plugin-wasm-pack@'; const pkg = 'pkg'; // default folder of wasm-pack module @@ -40,6 +42,9 @@ function vitePluginWasmPack( : moduleCrates; // from ../../my-crate -> my_crate_bg.wasm const wasmFilename = (cratePath: string) => { + if (outName) { + return outName + '_bg.wasm'; + } return path.basename(cratePath).replace(/\-/g, '_') + '_bg.wasm'; }; type CrateType = { path: string; isNodeModule: boolean }; From 0737eda95dfb555f14ae2dd61002af00a44ba434 Mon Sep 17 00:00:00 2001 From: Shnoorg Date: Mon, 2 Sep 2024 20:26:26 -0700 Subject: [PATCH 2/3] adds handling for JS file name as well --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f88b3ca..973d4a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -130,7 +130,7 @@ function vitePluginWasmPack( } } // replace default load path with '/assets/xxx.wasm' - const jsName = crateName.replace(/\-/g, '_') + '.js'; + const jsName = outName ?? crateName.replace(/\-/g, '_') + '.js'; /** * if use node module and name is '@group/test' From a0501925643775829914099738208fed7c476df1 Mon Sep 17 00:00:00 2001 From: Shnoorg Date: Mon, 2 Sep 2024 20:28:30 -0700 Subject: [PATCH 3/3] fixed .js getting dropped --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 973d4a1..8178ed5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -130,7 +130,7 @@ function vitePluginWasmPack( } } // replace default load path with '/assets/xxx.wasm' - const jsName = outName ?? crateName.replace(/\-/g, '_') + '.js'; + const jsName = (outName ?? crateName.replace(/\-/g, '_')) + '.js'; /** * if use node module and name is '@group/test'