wasm-tool / parcel-plugin-wasm.rs

wasm-bindgen support for Parcel bundler
MIT License
66 stars 16 forks source link

Update to match the changes in wasm-bindgen #31

Closed rrbutani closed 4 years ago

rrbutani commented 4 years ago

I tried to switch to using --target web (and --target node for node) as @Pauan suggested, but ran into some trouble. My attempt is here but the key points are that:

Just using the bundler target without any "custom parsing" doesn't work because parcel's built-in wasm loaders (here and here) don't pass in any imports.

By contrast, webpack does the right here which is why its' plugin doesn't need to remap the imports/exports and manually import the wasm blob. This other parcel plugin also uses the bundler target and remaps the imports and exports but then appears to go and replace the default parcel wasm loader with their own version that takes imports as an arg (this plugin effectively does the exact same thing, I think).

It seems like if this plugin were to use --target web and manually substitute the import.meta call for the actual file name of the wasm blob (and then also make it so parcel picks up and serves the blob) things would work. I'm not sure what the best way to do the latter thing is (raw asset? just copy it into the output directory? I know that putting it in generated under the wasm key won't work since, again, the default wasm loader doesn't support imports).

I'm also not sure that the workaround above (assuming it'd work) is actually appreciably better than the current way of doing things (it'd be more resilient to changes in how, for example, enums are exported in wasm-bindgen and that sort of thing but I don't know if it matters). In any case, I'm not very familiar with JavaScript build tooling so I thought I'd write all this out and make sure I'm not completely wrong about the above or missing something.

In the meantime, as the commit says, here's a stopgap that just goes and uses the _bg.js file where it's needed so things work as they did before.

This closes #30.

catsigma commented 4 years ago

thanks for the fix.