Uh oh!
There was an error while loading. Please reload this page.
Add watch and serve subcommands to wasm-pack - #10
Conversation
alexcrichton
left a comment
There was a problem hiding this comment.
Thanks for writing this up @fitzgen! I think this wasn't something I realized I wanted until you articulated it...
Long-term I'd love to explore possibilities of removing the static file server in wasm-bindgen-test-runner as well. If we could leverage wasm-pack's own internal server somehow that'd be great. I think that's pretty squarely outside the scope of this RFC, though, and we can deal with that later.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| -m, --mode <mode> Sets steps to be run. [possible values: no-install, normal, force] [default: normal] | ||
| -d, --out-dir <out_dir> Sets the output directory with a relative path. [default: pkg] | ||
| -s, --scope <scope> The npm scope to use in package.json, if any. | ||
| -t, --target <target> Sets the target environment. [possible values: browser, nodejs, no-modules] [default: |
There was a problem hiding this comment.
An interesting aspect of the serve command is that I think it basically doesn't work if you either don't pass -t or if you pass an incompatible value like -t nodejs.
I wonder if we should have some stricter validation (and documentation) which says that wasm-pack serve is only compatible with the no-modules and web (new) target?
| do their first build/serve offline, disconnected from the internet. This | ||
| seems like a niche enough situation that we can take the trade off. | ||
| * **Cons:** | ||
| * Building the HTTP server into the `wasm-pack` binary is less robust: by |
There was a problem hiding this comment.
FWIW this doesn't seem like too much of a con to me, if we were dealing with C/C++ I'd definitely agree but with Rust error recovery is pretty simple in-process.
That being said I still agree the next con outweighs the pro
There was a problem hiding this comment.
I wasn't thinking just memory, but also other resources like sockets, but yeah much less of a deal in Rust.
| * More work to implement. `wasm-pack` already has plenty of infrastructure for | ||
| downloading and working with external binaries, so using external HTTP | ||
| servers should be fairly easy to implement. | ||
There was a problem hiding this comment.
Thinking about this, one feature of webpack-dev-server is that when you request a page it actually waits to send any data until the current build is done. In that sense I think that a con of using an external binary is that we can't implement logic like that.
For example if I make a change and then quickly go and refresh a web page, I might get stale output if the build hasn't finished yet.
I wonder though if we could perhaps destroy --out-dir on each build to ensure that if the page is loaded stale artifacts are never served up? (not a great experience but perhaps better than seeing stale data)
| build profile, and the target environment. It takes extra options after `--` | ||
| that get passed through straight to `cargo build`. | ||
| Additionally, it has a `--no-watch` flag to disable watching the crate for |
There was a problem hiding this comment.
Maybe this should also be able to be controlled from wasm-pack's toml configuration? https://rustwasm.github.io/wasm-pack/book/cargo-toml-configuration.html
drager
commented
Mar 9, 2019
I think this is a great idea! Both commands and functionality makes sense to implement. I agree that if wasm-pack implements the |
Uh oh!
There was an error while loading. Please reload this page.
fitzgen
commented
Mar 11, 2019
Just pushed two more commits ådding an unresolved question about how to choose which files to watch and added a |
jrvidal
commented
Mar 14, 2019
Random thought out of the blue: there is a related, potential use case not covered by this RFC which is integrating with a JS bundler watch process (already hinted by @chinedufn I think) In a big JS project where Rust is introduced incrementally, it's very likely that there is already a bundler in place (with a sizable configuration) taking care of the watching and rebuilding. There currently exist a few Now, if OTOH, it's also possible to write loaders top of Of course this might very well be out of scope for an initial MVP, or for |
fitzgen
commented
Mar 18, 2019
I think we can split this scenario into two designs:
Most importantly, in both integrating-with-JS-bundler-watching scenarios, I don't see anything that needs to change in this RFC, or any fundamental design contradictions. |
The discussion here seems to have slowed down a bit, and there seems to be broad consensus that we want this general feature, and that we can continue to improve and evolve the subcommands during and after initial implementation. Therefore, I'd like to propose that this RFC enter its final comment period with disposition to merge. @rustwasm/core team members to sign off: |
alexcrichton
commented
Mar 18, 2019
Still quite a fan of this feature, so checking my box! |
Hey! So EDIT: I'm generally super in favor of this, and just anticipate I may have some design input, not that I would reject these features. |
alexcrichton
commented
May 6, 2019
Wanted to ping on this! @ashleygwilliams and @drager do y'all feel that wasm-pack is in a position where this can be reviewed/implemented? |
drager
commented
May 8, 2019
@alexcrichton I'm not sure in which sprint we can do this in wasm-pack at the moment. Both @ashleygwilliams and I have been pretty busy these last two weeks and we have a couple of issues left labeled sprint and some new issues I think we need to deal with and/or investigate. Personally, if we can fit some new functionality into the next sprint I think this should probably be one of those features. |
alexcrichton
commented
May 8, 2019
Note though that this isn't really about implementation work, for now this is purely just "needs a review and discussion on the RFC" style work. |
ashleygwilliams
commented
May 8, 2019
I'm on vacation but I 100% think we should open this up to conversation about design as we should be able to do this, likely not the next sprint (as originally intended) but the one after. |
boringcactus
commented
Oct 27, 2019
is there anything community members can do to help finalize this RFC? if we need more opinions about embedded vs external http handling, my opinion is that #10 (comment) is a good reason to build the server directly into wasm-pack instead of shelling out to an external server. having weird timing conditions where users can sometimes get stale data, or nothing at all, substantially weakens the user experience, which is a serious drawback in subcommands that are designed to streamline the user experience. |
boringcactus
commented
Dec 4, 2019
Also worth noting is that per rust-lang/cargo#7614 |
boringcactus
commented
Dec 5, 2019
I've thrown together a draft of a plausible implementation at wasm-bindgen/wasm-pack#745, partially out of curiosity and partially because @ashleygwilliams suggested that having a short turnaround time between design and implementation would be helpful. My implementation uses an integrated server and a |
- needed an http server to serve 'wasm' extension - I typically use nginx in one-time docker container run mapped to local directory to serve files - needed to add custom nginx config to serve "application/wasm" mime type - interested in adding info to Yew docs, looked at website which I then looked at Rollup example source - they recommend using python http server - found myself on Rust WASM RFCs github page with "watch and serve" command RFC - rustwasm/rfcs#10
jasonwilliams
commented
Dec 3, 2021
What's the blocker for this RFC? |
pastelmind
commented
Jun 12, 2022
This didn't work for me (using Rollup) when I integrated webpack into my build config, because it created an infinite loop. When wasm-pack rebuilt the Rust code, the regenerated I ended up running a separate watcher that only watches Rust code and invokes wasm-pack. |
jasonwilliams
commented
Jun 12, 2022
In the meantime if anyone is using esbuild https://github.com/Tschrock/esbuild-plugin-wasm-pack supports watching Rust files (as well as any JS files) |
Rendered
cc @ashleygwilliams@alexcrichton@DebugSteven@drager