-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Deploy both ES5 and ES2015+ code in production #3125
Comments
Wow @neeharv and I were literally just discussing this article and I came here to post this. This is an amazing idea—it feels like |
Thinking of an approach with |
My thoughts about this:
Or add webpack plugin like unminified-webpack-plugin that will convert all modern js files to ES5 style. |
/cc @addyosmani I recall seeing a tweet that this is horrible for performance. |
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 - entry: [require.resolve('./polyfills'), paths.appIndexJs],
+ entry: {
+ main: [require.resolve('./polyfills'), paths.appIndexJs],
+ esmodule: paths.appIndexJs,
+ } But there's no way to change
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
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! |
@geelen great work!
Totally agree with this. I guess we have to summon webpack gurus to find the best way to go. |
@Timer, I don't know the exact tweet you're referencing, but I'm sure it was about using the module loading feature and letting the browser load your entire dependency graph rather than using a bundler. The technique I describe in the article side-steps that performance issue by still depending on webpack to do the bundling. |
Thanks for the ping! Just had a chat with @philipwalton. The pattern he suggested in his article is fine to adopt and we reviewed it before it was published. It focuses on including a bundled top-level script using My performance concerns there have been that Chrome and other browsers currently haven't optimized the unbundled ESM use-case yet and we currently have lots of work to do bringing down IPC and parse/compile costs. Feel free to use the pattern in the article without any perf concerns from my side 👍 |
I'll be putting up a rough WIP PR on this soon, by turning the webpack config into a factory of sorts and calling the build function multiple times using a different target each time. It's a pretty hacky way right now, but it has the advantage of generating separate A potential problem with doing this using a webpack plugin is that it'll emit new files and add them to the manifest, and then plugins like Super excited about this, seeing a rough reduction of ~10% in the default bundle file size already for the ES6 build. |
@addyosmani thanks for the clarification! |
Landed basic WIP PR in #3136, we need to figure a better way to do this. Would love to hear some suggestions! |
I think it's a cool idea in theory but I don't see how it could progress unless Webpack gets 10x better at caching. We are already blamed for very slow builds; can't make them twice as slow. |
I reckon you'd only need the legacy build on production builds and not development builds, so it would only affect the production build time, no? Does that make a difference? |
Yes, production build time is the one people are struggling with. |
I don't really see us increasing complexity to support this. |
yea, maybe someone can build a package that simplifies this. 😉 |
...so this is dead? Has anyone built like a plugin or something? I would really love to have this feature for performance and debugging. |
@MidnightDesign cra v2 uses browserslist |
@Djelnar Does that imply that this should work now? How? |
Is this a bug report?
No
Everything described in this article.
But for lazy ones I'll add some highlights here.
And here is the working example.
The text was updated successfully, but these errors were encountered: