vite-plugin-wasm-pack icon indicating copy to clipboard operation
vite-plugin-wasm-pack copied to clipboard

Project does not work with renamed packages

Open SnowyCoder opened this issue 2 years ago • 0 comments

It's not unusual to have wasm-pack packages exported with different names, and since this is not yet supported by wasm-pack people have been using sed to replace the "name" field in package.json (https://github.com/rustwasm/wasm-pack/issues/427).

This plugin does not seem to work when the imported package name fails to match the package files. I tried to open a pull request but I'm new to rollup/vite plugin and I don't want to waste the next 5 months trying to reimplement classic-js resolution algorithm, so I'll leave this issue if anyone wants to work into it.

As a workaround you can use this in your wasm-pack Makefile to rename "my_module_wasm" into "my_module":

sed -i -e 's/my\([-_]\)module[-_]wasm/my\1module/g' pkg/package.json pkg/my_module_wasm.js
for f in pkg/my_module_wasm*; do mv "$$f" $$(echo "$$f" | sed 's/my_module_wasm/my_module/g'); done

The double $$ are required to escape bash variables from make.

SnowyCoder avatar Jun 30 '22 08:06 SnowyCoder