-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Bundle size is bigger than necessary due to ES6 imports #5079
Comments
I don't know enough about tree shaking to give any real input on this, but I will mention that this is related to #4432. |
The ES build with webpack 2.3 does not solve the issue. Only changing all the imports improved the situation since any import to react-router will bring in all the modules. |
Are you sure you're using the ES build? It leaves import/exports untouched, so Webpack should be able to tree-shake it. I'm thinking this is either some misconfiguration of webpack or babel on your end. Unfortunately, it's easy to mess up because Webpack doesn't make it obvious when you're actually using ES modules or not. |
These issues might be relevant. webpack/webpack#4080 Also the image above was with using a babel plugin (babel-plugin-transform-imports) to do direct import otherwise the bundle looks like this. Nothing gets removed. |
But are you sure it's using the es build that's included in the npm package? That's the key thing. What if you alias react-router to react-router/es? |
I am sure (notice the 'es' folder above in the screenshots) and have tried the alias with the same result. So I am pretty sure that the build is pointing to the ES build. My question is whether a PR would be accepted with a change to fix this problem. |
Sure, but what would be the appropriate change? AFAIK, we're doing the same thing on Redux and it works fine there. |
The change would the react router dom export refer to direct import instead of importing the top level of react-router. I have tried this locally and it did fixed it. |
Would fixing this issue solve this you think? @ruiaraujo. I've recently upgraded to webpack 3 and am trying to optimize my bundle with the new
|
@chrisdl That is odd. You can try that branch in your local project and report back. |
@ruiaraujo im actually having some issues installing the PR locally. Is there a better way than using to your knowledge?
|
Do you know about babel-plugin-import? |
I am using react-router-dom and webpack 2 and it seems the tree shaking does not work well enough to remove unused modules.
I managed to fix it locally by changing the import style from
to
everywhere.
Version
4.0.0
Is this something that would be interesting to do a PR on?
The text was updated successfully, but these errors were encountered: