Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using a custom loader #1686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tiennou
Copy link

@tiennou tiennou commented Feb 20, 2024

Rollup Plugin Name: rollup-wasm

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes
  • no

Breaking Changes?

  • yes
  • no

Description

This deprecates the targetEnv option and replaces it with loader which performs the same thing while also accepting an actual function.

When that happens, that function's body will be inserted in lieu of the default one, giving complete control over the way WASM is loaded into the runtime.

I need it because I'm trying to load code in a sandboxed Node 10 environment, which doesn't have process nor Buffer available, and that felt like the cleanest way to do that without giving you a bunch of hardcoded code that's meaningless outside of it.

This deprecates the `targetEnv` option and replaces it with `loader`
which performs the same thing while also accepting an actual function.

When that happens, that function's body will be inserted in lieu of the
default one, giving complete control over the way WASM is loaded into
the runtime.
@tiennou
Copy link
Author

tiennou commented Feb 20, 2024

My initial attempt at this was to give a function name from the bundle instead of something that would only live in the config. But I couldn't find a way to get the mangling done by Rollup to apply to it from inside the plugin; that's why I settled on having a real function.

In other words, if I had set loader: 'myCustomLoader', that would translate to something like this in the final bundle:

function wasm (imports) { return myCustomLoader(0, null, 'AGFzbQEAAAABBwFgAn9/AX8DAgEABQMBAAAHEAIDYWRkAAAGbWVtb3J5AgAKCQEHACAAIAFqCwAkEHNvdXJjZU1hcHBpbmdVUkwSLi9yZWxlYXNlLndhc20ubWFw', imports) }

/* somewhere else */

function myCustomLoader$1(sync, path, src, imports) { /* … */ }

and that $1 prefix would have been a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant