Deploy both ES5 and ES2015+ code in production
See original GitHub issueIs this a bug report?
No
Everything described in this article.
But for lazy ones I’ll add some highlights here.
<!-- Browsers with ES module support load this file. -->
<script type="module" src="main.js"></script>
<!-- Older browsers load this file (and module-supporting -->
<!-- browsers know *not* to load this file). -->
<script nomodule src="main-legacy.js"></script>
Warning! The only gotcha here is Safari 10 doesn’t support the nomodule attribute, but you can solve this by inlining a JavaScript snippet in your HTML prior to using any <script nomodule> tags. (Note: this has been fixed in Safari Tech Preview, and should be released in Safari 11).
And here is the working example.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:20 (9 by maintainers)
Top Results From Across the Web
Deploying ES2015+ Code in Production Today - Philip Walton
When run, these two configs will output two, production-ready JavaScript files: main.mjs (the syntax will be ES2015+); main.es5.js (the ...
Read more >Why does Angular build create files with 'es5' and 'es2015' but ...
Angular doesn't bundle the JavaScript files into a single file. You can add a build step to concat the files together. concat-build.js:
Read more >Deploy Angular apps with ES2015, today - Medium
Our approach is to generate “two apps” from the same source code, ... we have a default app with ES2015 and a “legacy”...
Read more >Deployment - Angular
For the simplest deployment, create a production build and copy the output directory to a ... ES5 support enabled, es2015, Differential loading (two...
Read more >Understanding ES5, ES2015 and TypeScript - John Papa
What is the difference between ES5, ES2015 (formerly known as ES6), ... is a lot of ES5 code and it's good to understand...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
…so this is dead? Has anyone built like a plugin or something? I would really love to have this feature for performance and debugging.
Ok, after a few hours of hacking, this is what we’ve found:
This feels like the nicest idea, where you now have two entry points (in
webpack.config.prod.js
):But there’s no way to change
babel-preset-env
in the config, depending on the entry point.If you duplicate your production webpack config, you can handle things pretty well, but that has the weakness of… well… duplicating your production webpack config. @neeharv has gotten a build working pretty well using this so I might let him describe it.
One thing worth pointing out is that we had to use the beta version of UglifyJSPlugin to get the ecma config property, otherwise ES6 code would break. So CRA would probably need to bump to whatever version of webpack includes this, once it goes stable.
This is where my thinking is at atm. If your webpack plugin targets beautiful new ES6 code with no polyfills and very little transpilation, but then something comes along and transpiles it to ES5. I’ve played around with
unminified-webpack-plugin
a bit and tried to get something similar working, but don’t know webpack really well enough to ship this quickly. What it would need to do, though, is this:.nomodule.js
or something similartype="module"
forindex.js
,nomodule
fornomodule.js
)This does feel like an achievable goal, and makes sense to be done as a webpack plugin. There are still questions around serviceworker, given that it reads from the manifest, but we haven’t got that far yet.
So that’s where we got to in a couple of hours hacking. I think this is a really cool idea and has the potential to dramatically cut down bundle sizes for modern browsers, so would love to see this progress!