Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 };
Expand Down Expand Up @@ -125,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'
Expand Down