-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cannot use "watch" with "serve" #805
Comments
Short answer: Maybe soon but not yet (to the best of my knowledge). I believe you’re right that this is not yet implemented.
That all being said, this can be implemented using the Node or Go APIs by adding a callback to // ...
watch: {
onRebuild(error, result) {
if (error) console.error('watch build failed:', error)
else console.error('watch build succeeded:', result)
},
},
// ... https://esbuild.github.io/api/#watch The basic idea is that when esbuild rebuilds (because your source changed), you send a signal to the browser via server sent events / WebSockets (this is the motivation behind #802, to make this a managed experience by esbuild -- as you noted). |
No, you can't use this feature to replace The |
Just to be clear, I'm interpreting that the only way to add live reloading (for now) is to avoid I would love to use For context I see this when trying to just hook up the (node:93344) UnhandledPromiseRejectionWarning: Error: Cannot use "watch" with "serve" |
Yeah I was a little surprised that you can’t use them together. But I don’t know if that was an intentional decision or is simply unimplemented. Insight would be appreciated here. Anyway, @dzearing, you can just use both, right? Start a watch server and then also start a serve server. If you need to get the browser to update in response to watch events, that’s probably just a matter of hooking up server-sent events or websockets. In my experience I’ve found implementing SSE (server-sent events) to be pretty simple and fun. So doing so you’d get the in-memory perf you’re looking for. I’ve found esbuild’s API to actually be pretty loosely coupled and therefore composable. It can take a little getting used to but it turns out to be a very powerful API because you can shape esbuild into the kind of tool you need pretty easily. |
@zaydek Oh! I totally forgot there's a config setting to use in-memory building - so yeah, I could probably use watch mode, then have express serve up the script from in memory results, and I'll spin that up and see how it goes. |
Hmm. I am using If there's a way to access the watch mode in-memory build results from the And if there's a workaround to getting the |
Ah. That kind of makes sense. But why not just write to disk then? Yeah, I think I know what you mean about mixing callbacks together. I think my strategy so far has been to create an uninitialized function and then initialize it lazily. This kind of thing in Go is a bit easier because you can orchestrate w/ channels but in JavaScript it’s a little awkward unless you know exactly what you’re doing. |
@zaydek Mainly I'd love to minimize disk writes and make the inner loop It does feel kind of broken to have @evanw would you consider it worth fixing to expose Thanks for the help! |
I'm not sure if this is the intended behavior, but.... If I use So, if you want |
Nevermind on the above |
Hey @David-Else, I was using |
for those willing to use |
It might be that it works only from cli, and not from node? |
There is a working solution found here |
Hi, I am trying to replace
live-server
for my development with the new--servedir=
but having problems getting it to watch the files and serve them. Currently, I have:As soon as I save then the browser reloads the file. I see #802 , but I don't see the use for
--servedir=
unless it refreshes when the files changes somehow?Can I now replace
live-server
with esbuild or am I confused about the new feature? Cheers.The text was updated successfully, but these errors were encountered: