-
-
Notifications
You must be signed in to change notification settings - Fork 208
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 #478
Comments
@sayjeyhi polished is fully tree-shakeable and has been for a couple years now. FWIW I don't think Bundlephobia is evidence that something isn't properly tree-shakeable. Here is another example where it is incorrect with styled-components: https://bundlephobia.com/[email protected]. We will need more information about your setup to provide any help on why it isn't working in your particular instance:
Our docs also link to how to set this up in webpack and rollup: https://github.com/styled-components/polished#usage |
@bhough I'm aware of sub-module imports. But we can't really classify that as a solution can we? Tree shaking is designed to work on re-exported modules at the root level. There has to be a reason for it to break only on this library. |
@avin-kavish This is still an open issue @sayjeyhi is just suggesting an interim solution. We've been unable to recreate this yet. If you'd like to provide the info we asked the OP for, we can continue to dig into it. One thing that usually catches people is they are running their bundle analyzer on a development build vs the production bundle. In development, you will see the entire library. When you use the method described above, you will see just this file imported into the development build directly, which is not the same thing as the tree-shaking going on in the production build. |
@bhough maybe I could work around it this weekend and come with a PR... |
@sayjeyhi All we really need is a link to a repo we can fork that shows where it isn't tree-shaking and can take it from there. |
@sayjeyhi the screenshot is |
Yeah, it works with minimal code, trouble happens when there's a complex tree of dependencies.
So I created a tree like this in Next.js (which is where I am having the trouble) but I can't get an accurate size because of module concatenation. I will keep experimenting... Edit: With module concat turned off, it's only adding 2.5kB so no go once again. |
Not sure what you mean by 'no go once again'? The fact that it is only adding 2.5kB should mean it is working correctly. Keep in mind color modules are relatively heavy given their dependencies. |
I was trying to create a reproduction of the issue in a code base separate from the one I'm having the issue in. I can't share the original as it is not open source. What I mean is that the issue is likely due to some weird interaction between dependencies etc in much larger/complex code. |
K @avin-kavish We will keep this up for the time being to see if we can get a recreation. Only issue we've seen is folks pulling in the non-es-module version from the |
I see. I don't think that's happened in my case based on the screenshot below. It seems that polished.es.js is imported. Maybe the following info could be helpful? yarn why polished
Bundle AnalyzerFull Bundle with Polished: 432kb. How did I remove only
|
@avin-kavish That's good context. The fact that it is being pulled in from another dep could be significant. Could be something |
Could it be this? exports.__esModule = true;
var _components = require("./components");
Object.keys(_components).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
exports[key] = _components[key];
}); Their exports seems to be dynamically defined. |
I'm running into this issue as well, |
☝️ same issue as @twdrake-ap. On a basic Gatsby project, using |
Same issue. 🤔 Simple workaround. |
@hipstersmoothie disabling source-maps is a no go for me because they're needed for debugging errors in production |
|
Hi there,
I was analyzing my packages and figure out that all of polished function did imported and impact my bundle size.
I just used
darken
andlighten
functions.here is bundlephobia which tell all single function has same size as all package :
https://bundlephobia.com/[email protected]
see Exports Analysis part
The text was updated successfully, but these errors were encountered: