-
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
[WIP] Introduce an All
target for outputting all supported module types by wasm-pack
#705
base: master
Are you sure you want to change the base?
Conversation
I haven't reviewed this deeply, but I wonder if Instead, I think supporting multiple |
@Pauan multiple people have requested an all or "isomorphic" target for publishing cross compatible packages to npm. i do like your suggestion that perhaps the targets are configurable- strikes me as something we could have folks do in a Cargo.toml! |
All
target for outputting all supported module types by wasm-packAll
target for outputting all supported module types by wasm-pack
@@ -54,6 +54,8 @@ pub enum Target { | |||
/// in a browser but pollutes the global namespace and must be manually | |||
/// instantiated. | |||
NoModules, | |||
/// Correspond to `--target all` where the output is all other targets | |||
All, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given @Pauan's comment and the likelihood that folks will want to customize the types of targets they want... i could imagine that instead of an All
type, you have a new type that is a Targets: Vec<Target>
- and for just Node, the Targets would by Vec<Nodejs>
, and all would be Vec<Web, Nodejs, NoModules>
@ashleygwilliams I know, but my point is that |
@Pauan i think you and i are agreeing with each other! the one difference is that i think aliasing this task is so common that i dont think it's reasonable to make it burdensome with an overly verbose command, and target feels like the property of a project so putting it in the project config makes a lot of sense i think |
Sorry for the late response, was having a fun time at RustConf! π @Pauan Thanks for the feedback π So what's the plan here? I see 3 things here that I think would be worth getting an agreement on π
In my opinion, I think my answer to each question depends on each of the answers to the above. But reading what we currently have, I think maybe it's worth proceeding like this: As CLI Flags
As
Thanks everyone! π π Let me know what you think! |
User waiting on this feature weighing in:
Basically, in my ideal world, I don't think any of these ideas are at odds. I'm also pretty impatient waiting for this to land as I've been struggling with this kind of issue all week, so take everything here with a grain of salt. |
Thanks for the feedback @rivertam ! π Going to bump this to @ashleygwilliams and @Pauan if they don't mind π As I want to get a plan going before I write more code π |
@torch2424 I can't speak for Ashley, but this is my personal opinion:
|
|
@cormacrelf Being surrounded by quotes is okay too, but @torch2424 mentioned space separated without any quotes. The reason spaces don't work is because then it can't tell the difference between a |
Totally okay with not being space separated. If cargo is currently using quotes, than I think using quotes and being space separated within the quotes makes sense π That being said, to just push things along for users like @rivertam , let's proceed as follows: CLI Flags
I'll wait for a final thumbs up from @ashleygwilliams (I'll ping them on discord as well) and then start on the new PR π π |
Thanks @torch2424. I appreciate you. It's worth noting I used your branch to create a similar as your branch makes: package.json: {
"name": "my-package",
"collaborators": ["Ben Berman <ben@standardbots.com>"],
"version": "0.0.0",
"files": [
"my-package.bundle/my-package_bg.wasm",
"my-package.bundle/my-package.js",
"my-package.bundle/my-package.d.ts",
"my-package.node/my-package_bg.wasm",
"my-package.node/my-package.js",
"my-package.node/my-package_bg.js",
"my-package.node/my-package.d.ts"
],
"main": "my-package.node/my-package.js",
"module": "my-package.bundler/my-package.js",
"types": "my-package.bundler/my-package.d.ts",
"sideEffects": "false"
} then I bundle the package with
and I think this results in basically the same output as I want, so for me and presumably for anyone who reads this comment, the issue isn't too urgent anymore. This workflow is actually totally fine for me, and I'm no longer awaiting this PR because of this. That said, obviously this is a useful feature. |
This would be really valuable improvement for npm packages targeting node and webpack. Managed to get single npm package to work for both node and webpack using manually created package with separate glue js and wasm files for different platforms: https://github.com/tlaukkan/rust-ray-intersect-js/tree/master/pkg The node glue js and wasm files have not been modified.
vue-cli-service webpack config is:
Glue js required async init() call to instantiate WebAssembly module asynchronously as Chrome requires this for large modules. In the end it might be necessary to have separate target for creation this kind of isomorphic packages. |
+1 for this feature. Any help needed to progress the PR? |
Looking forward to this. π It simplifies many things. |
Yoooo! What's up @aminya haha! π So, this PR got a bit stale, as I was waiting for some confirmation on the right way to move forward on the PR. And now, I don't really have the time to fix up this PR. π’ Though, I would be more than happy if someone were to take over the PR and things π |
Is there any way to manually accomplish this at present? I would like to be able to make an isomorphic package which uses a wasm-pack sub-package, ideally without needing a bundling step (for Node, something will still be needed for browser). The idea would be for my isomorphic package to be able to Problem is that I don't think there's any current target that will make it output for Node using ES modules. Any ideas? What are people currently doing to make isomorphic packages? |
@curiousdannii Yeah, check out my comment earlier. That works for me. |
In our project we generate a nodejs and browser compatible package with wasm-pack and have a top-level package.json which is published like so: https://github.com/cennznet/doughnut-rs/blob/2af67a162f650e993779642c6879a110fad7a498/js/package.json#L5-L6 Poking around the project may give you some ideas: https://github.com/cennznet/doughnut-rs/tree/master/js The main issue we're seeing with this approach is it generates 2 wasm blobs which blows out the package size |
@rivertam The @Holygits It looks like you're outputting CommonJS for Node and ESM for browsers, which is not an isomorphic package like I'm hoping can be achieved, as dependent packages would need to consume it in different ways, so they could not themselves be isomorphic. I'm thinking that to get an ESM Node module I'll have to run the |
@curiousdannii I'm not sure what you mean. The method I describe above includes a package for both bundler and node. I'm not sure whether the bundler works for Rollup. I have the following setup:
This topology works fine for me with the method I describe above, bundling both |
@rivertam I want package A to be able to |
@curiousdannii it's hard for me to understand what the problem is because that sounds exactly like what I'm describing to me. A is sometimes used in node and sometimes with webpack, and they both work. |
@rivertam Could it be that you're not running into issues because either Jest or TS is rewriting your If not, well I don't know then. Hard to say what's different in our setups. |
@curiousdannii Err... I'm pretty sure Jest/TS are rewriting to |
@rivertam Node has supported ES Modules natively for years (behind flags originally, though they're not required anymore), so you're not supposed to rewrite them to CommonJS. And even if you use TS, it can output ESM too. It's perfectly reasonable to ask for a tool such as wasm-pack to output ES Modules for Node, and if you want to make an isomorphic package without further build steps, it's necessary. |
Ah, I see. I wasn't aware that node natively supported modules at this point (and it appears it's still experimental as of node 15) but I see the problem now. Does it work in node if you export with target |
Until something like this PR is merged, I'm expecting I'll just have to run the |
Make sure these boxes are checked! π¦β
rustfmt
installedcargo fmt
on the code base before submittingβ¨β¨ π Thanks so much for contributing to wasm-pack! π β¨β¨
Description
relates to #697
closes #313
This introduces a
--target all
flag that will run wasm-bindgen for all of our supported outputs, prefixing them with a_[MODULE TYPE HERE]
. And then adding all of the files to the resulting package.json.Things still to do
.mjs
π cc @stephanemagnenatcc@alexcrichton @ashleygwilliams
P.S I wrote the last half of this at 2AM. So the code may be terrible, but I figured we could get through this together π
Output