Deploying ES2015+ Code in Production Today
philipwalton.com
philipwalton.com
[1] https://www.npmjs.com/package/@std/esm [2] https://medium.com/web-on-the-edge/es-modules-in-node-today-...
The old way of doing things was write for node, and transpile/polyfill the browser with browserify/webpack/etc. But the amount of bytes you ship to the browser really matters. So now the new way of doing things is to write for the browser and transpile/polyfill node which is what @std/esm is doing.
This is explained a little better in the r2 readme:
It makes sense from the Node side of things too, because there's an ability to sometimes borrow the browser-hardened native implementations of "web" APIs directly from partner tools like Chromium, v8, and even ChakraCore. A rising JS tide can lift all boats, and the more "universal" the web platform is the easier it is to develop for.
Also, File I/O is still a bottleneck in Node, even if nowhere near the bottleneck of browsers requesting files over HTTP, and it feels like webpack/rollup is starting to be more of a thing on server-side/NodeJS side, because there are benefits to reducing the bytes you need to read from disk in startup times of NodeJS apps, too. So it's interesting seeing some optimization tools converge on that side of the fence as well.
What is everyone's cutoff for de-supporting a browser? According to caniuse.com[1], >30% of browsers don't support the mentioned feature-set; that seems like … a lot.
(<script type="module"> is listed at 60% unsupported, which seems very high, but his point that if you allow it, you should allow everything else mentioned seems sound. I also heavily agree w/ his point about delivering modern JS, and letting end consumers transpile as needed.)
http://www.everyi.com/by-capability/maximum-supported-ios-ve...
So it depends a little upon your user demographic (or whether you want to keep supporting users or companies that can’t afford to upgrade their device).
So, while you may be able to get your code to run on them, it might not be a great experience and of limited value to your customers to even try offering support.
During AB tests, sales actually went up
The author proposes using 2 webpack configs, one for es2015 and one for es5. That means running webpack twice from scratch. This, in turn, means you can't effectively use webpack's devserver because that's just a single instance with a single webpack config.
The author's boilerplate [0] "solves" that by hand-coding a watcher based on chokidar which just rebuilds both files on every change. On our code base, clean webpack builds take minutes (and when babel is even configured to exclude /node_modules/, as the author recommends against). If we'd follow the author's advice, we'd be waiting for minutes every time we make a change.
Anyone got a good idea here? The best I can come up with is to use the es2015 build (but with node_modules excluded) in dev mode, and then for staging and production, running webpack twice as the author suggests. That makes the dev version rather different from both the production es2015 output and the production es5 output, however, so if there's any bug in the chain anywhere (babel bug, webpack bug, babel-env browser support table error, etc etc) we may not always find it.
In all honesty that itches me a bit (even though by skipping uglify in dev mode we already depend on at least 1 tool being essentially bug-free). Any ideas?
[0] https://github.com/philipwalton/webpack-esnext-boilerplate
[EDIT: it looks like this is already supported, here's the documentation explaining how to do it: https://webpack.js.org/configuration/configuration-types/#ex...]
Service Worker already introduced the need (or you could argue possibility) to have multiple configs since SW code has a much different transpiling baseline compared to legacy browser code. And module code just adds one more level to this.
I think webpack dev server will update if this practice becomes popular, but for the moment I think your idea of only building the es2015 build in dev mode is probably the best temporary solution (as long as you make sure to run your test suite in multiple environments and include the legacy build there).
See https://github.com/webpack/webpack-dev-server/blob/master/ex... for a simple example. I've used this before for web worker scripts (which require a different environment than the DOM) alongside a normal build.