-
Notifications
You must be signed in to change notification settings - Fork 409
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
Support both Node.js runtime and bundlers by default, out-of-the-box #469
Comments
hi @KSXGitHub ! this is a pretty common request that we get and something we fully intend to implement starting after the most recent release comes out! |
@ashleygwilliams Since you tagged this as "duplicate", can you also give me the link to the original issue? BTW, this issue isn't a mere request, but also a small suggestion of how this could be implemented. |
and i understand that it's a suggestion for implementation- we already have a pretty good idea of how we'd like to do this (very similar to what you have suggested- except we are not interested in supporting .mjs at this time) - just need to do it! |
@ashleygwilliams Thanks.
What prevents you guy from doing this? |
i think at the moment it's still experimental and in the interest of keeping wasm-pack simple, we don't want to support experimental targets. once node stabilizes it we'll add support. |
closing in favor of #313 - going to copy your suggestions here into a comment on that issue. looking to do this for the 0.10.0 release |
hi, could this work now? |
When I write an NPM package, I rarely think of bundlers as they can comprehend
require()
syntax, so as long as I only userequire()
to load module, I don't worry about bundlers. This is not the case with Node.js WASM modules generated bywasm-bindgen
as it usesfs.readFileSync
(which cannot be polyfilled by bundlers) to load.wasm
file.wasm-pack build
currently supports 2 targets:--target browser
support bundlers (today's browsers cannot load the output script/module directly) but not Node.js.--target nodejs
support Node.js runtime but not bundlers/browsers.This is inconvenient, if I want to support both targets, I have to write my own wrapper that calls
wasm-bindgen
twice.Suggestion
Without options, generate 4 files for 4 targets:
index.bundler.js
for JavaScript bundlers, set"browser"
field inpackage.json
to point to this file.index.js
for Node.js runtime, set"main"
field inpackage.json
to point to this file.index.mjs
to work withnode --experimental-module
,"module"
field ofpackage.json
may or may not point to this file.index.script.js
to work with<script>
tag (I want to be able to test this directly in browser console).Deprecate the use of
--target <target>
in favor of--nodejs index.js
,--module index.mjs
,--browser index.bundler.js
, and--script index.script.js
.Additional Suggestion
Please don't use package name in
Cargo.toml
for JavaScript entry files, useindex.*
like most NPM packages.The text was updated successfully, but these errors were encountered: