rapier-inject - a new package for using rapier-compat without an inlined wasm file #193
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.
In some environments (namely, cloudflare workers), fetching wasm binaries (even from data urls) is disallowed. In addition, cloudflare workers don't support top level await, and it's not on the roadmap.
However, cloudflare does support uploading a wasm binary and importing it (which will import a module ready for instantiation).
This solution is similar to what was proposed in #30, but is a slightly lower hanging approach than making the entire API async - instead, it just borrows the
init
pattern from-compat
and requires that you provide the wasm file (which can be referenced from the package). Because it is imported as a module, bundlers will find and include the wasm binary, resulting in this working as expected.Usage ends up looking like this:
I realize this may not be as elegant a solution as would be possible with some more work, but for me I just needed to unblock a workflow running rapier on cloudflare and this allowed me to preserve some isomorphic logic because I can now inject the normal
@dimforge/rapier3d
on the client, and the new injected version in the worker.As for implementation, I just wrote a quick script that copies the
-compat
package and overrides theinit.ts
scripts and the rollup config.