Skip to content
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

Tree shaking does not work on dependencies of dependencies #6943

Closed
carpben opened this issue Apr 28, 2019 · 7 comments
Closed

Tree shaking does not work on dependencies of dependencies #6943

carpben opened this issue Apr 28, 2019 · 7 comments

Comments

@carpben
Copy link
Contributor

carpben commented Apr 28, 2019

Converting from ES6 named imports, such as

import {faTimes} from "@fortawesome/pro-light-svg-icons"
import {Range} from "rc-slider"

to specific ("cheery picking") imports, such as

import {faTimes} from "@fortawesome/pro-light-svg-icons/faTimes"
import Range from "rc-slider/es/Range"

reduced bundle size from 1.01MB to 870kb.
I know that this is what we should expect from Lodash, but that tree shaking is possible with named imports . Could it be that CRA, due to its Babel-Webpack configuration, blocks "tree shaking" for named imports?

Project details:
"react-scripts": "2.1.5",
Typescript

Resources: optimizing-js-tree-shaking-1, optimizing-js-tree-shaking-2

@carpben carpben changed the title Convertin from ES6 named imports to specific ("cheery picking") imports reduced bundle size significantly. Can "Tree shaking" be improved for named imports? Can "Tree shaking" be improved for named imports? Apr 28, 2019
@stale
Copy link

stale bot commented May 28, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label May 28, 2019
@carpben
Copy link
Contributor Author

carpben commented May 29, 2019

@iansu, @ianschmitz, Do you mind sharing your opinion?

@stale stale bot removed the stale label May 29, 2019
@stale
Copy link

stale bot commented Jun 28, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@simonssspirit
Copy link

We are also interested in this improvement.

You can change your own imports, but in cases with third party packages which use name imports internally, you have no option to change it.

@Dan503
Copy link

Dan503 commented Dec 15, 2019

The core of this issue is that tree shaking does not work for dependencies of dependencies.

My use case:

Our company has a component library. The component library is distributed through npm as a project dependency. At the individual project level we can use icons from material-ui by using the condensed syntax:

import { icon1, icon2 } from '@material-ui/icons'

In our component catalogue we are forced to use the expanded syntax:

import icon1 from '@material-ui/icons/icon1'
import icon2 from '@material-ui/icons/icon2'

When you have a lot of icons to import, this method is ugly and verbose.

If we don't use this method in the component catalogue though the entire material-ui icon library downloaded adding an extra ~5MB to the site weight.

This is because the component catalog is the dependency and the icon library is the dependency of the dependency.

In my case, we have a way to avoid this but if there is a third party library that is using the condensed import syntax, there is no way to avoid it.

@Dan503
Copy link

Dan503 commented Dec 15, 2019

Can we please change the name of this issue to "Tree shaking does not work on dependencies of dependencies"?

That is what this issue is all about. The current name is a bit vague as to what the problem is.

@ianschmitz ianschmitz changed the title Can "Tree shaking" be improved for named imports? Tree shaking does not work on dependencies of dependencies Dec 16, 2019
@carpben
Copy link
Contributor Author

carpben commented Dec 18, 2019

@Dan503, Thanks, this was very helpful.

I think you just answered the original title "Can "Tree shaking" be improved for named imports?". According to your answer it's an issue of the dependencies, perhaps the bundler, not of CRA.

However, I disagree about the title. I posted a question, and was clueless about the answer. Changing the title is misleading, and also confusing as it does not go along with the original post. So unless I'm missing something I think the original title is more suitable.
@ianschmitz

@carpben carpben closed this as completed Dec 18, 2019
@lock lock bot locked and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants