-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add watch
and serve
subcommands to wasm-pack
#10
base: master
Are you sure you want to change the base?
Conversation
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.
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.
-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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
I think this is a great idea! Both commands and functionality makes sense to implement. I agree that if wasm-pack implements the |
Just pushed two more commits ådding an unresolved question about how to choose which files to watch and added a |
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 |
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: |
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. |
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? |
@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. |
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. |
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. |
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. |
Also worth noting is that per rust-lang/cargo#7614 |
I've thrown together a draft of a plausible implementation at rustwasm/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
What's the blocker for this RFC? |
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. |
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