Update to match the changes in wasm-bindgen #31
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:import.meta
in the JS thatwasm-bindgen
produces with--target web
is problematic because:parcel
can't see through that importbabel
doesn't yet support this (Enable import.meta by default in @babel/parser babel/babel#11364)import.meta
can only be used within an ES module which is problematic for the output thatparcel
producesJust 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 theimport.meta
call for the actual file name of the wasm blob (and then also make it soparcel
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 ingenerated
under thewasm
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.