Proposal: Don't start serving until the bundle has been written
Closed this issue · 3 comments
I'm hoping this will help with people requesting http://localhost:5000/bundle.js before the file's ready, which hopefully will get rid of the epidemic of the "unexpected token <" errors.
What if we didn't start npm run start:dev
until the writeBundle
hook in Rollup has been called? This could be called with child_process.exec
or something in a one-off plugin that's only used when we're not in production mode. If the server's not even running yet, hopefully the browser won't try to cache anything.
As an added bonus (and this one would be worth it by itself imo) we would be able to drop npm-run-all
which has twelve trillion dependencies.
Another possibility — we use something like https://github.com/thgh/rollup-plugin-serve, which I think probably handles these cases. It's designed to work with rollup-plugin-livereload (same author) which we're already using
What does that use to serve the files? One of the reasons I suggested this was that we could continue to use sirv for serving in dev mode, like we do in prod.
edit: I suppose there are warring goals here, of "have what you do in prod and what you do in dev differ by as little as is practical" and "sirv was never initially intended for dev mode, which was added as an afterthought". I don't know who wins out.
edit again: Another argument against rollup-plugin-serve is that it's a new dependency. I dunno.
I don't know, but for the record, I use both of them when developing a FE app on rollup. The dev-mode in sirv is poorly named as it's only really meant to be a cache bypass.
Eventually I'll get around to finishing my HMR until, which would integrate with rollup and sirv... But for now my bandwidth won't allow that anytime soon.