-
-
Notifications
You must be signed in to change notification settings - Fork 990
Support Tree Shaking / Modularized Imports (React) #359
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
Comments
That's pretty important |
Looking forward to seeing progress too |
I'm working on it here: #378 :) |
You're awesome @codecalm! |
thanks @codecalm , what's the best option now using v2 on next for decrease bundle size? |
Much needed, thank you! |
Is it possible to use with modularize imports from next? I'm using 2.0.0-beta from react-icons but it seems I cannot remove Icon prefix from member
This is the route for Icon:
Is it possible to transform? I cannot remove (Icon)24-hours
Thanks! |
@markitosgv check |
Thank you for the hard work on that huge release @codecalm ! Unfortunately, it didn't work. I took a look at the package release, and I can see why. The naming is not consistent between the exported value and the file itself:
And so a configuration like this will just point to a non-existent file:
I noticed that @markitosgv already warned us about this from the beta release last week. I can confirm that the prefix is the issue here, I can't remove it, and so I can't modularize imports. |
so, if I ranamed icons from |
@codecalm we can get around the casing with |
so it should be |
@codecalm exactly, same as the import. But before you put any work in, I think I found a workaround, they do support regex: Let me attempt that right now and follow up |
yeah, I read this article and regex section and I think that will be problem with |
@codecalm agreed, I gave it my best shot but unfortunately I think there's nothing we can do without a rename.
|
Also just to clarify for this ticket, the issue isn't tree shaking, but of the import tree. Webpack needs to traverse the entire import tree regardless of tree shaking (which happens during minification). This slows down the build process whether you are performing a dev or prod build, but it creates noticeable performance problems in dev when they all get loaded in memory. I filled a ticket on @mui for the same problem: mui/material-ui#35840 |
Yes it could be icon-xxx or IconXxx but we need Icon prefix for nextjs transformation work . And I think is more consistent naming Thanks |
@codecalm would this be considered a |
@anthonyalayo 2.0.1 |
@anthonyalayo I've opened PR: https://github.com/tabler/tabler-icons/pull/468/files what do you think? do I need add something to |
I think it's ok! new names for files will be IconHome.js ? |
yes, exactly |
@codecalm i'll try it out right now locally |
@codecalm i'm struggling to get the build going with ruby (osx compile issues). If the outputted files are the same name as the variables, we're good to go |
I've compiled it and everything looks good :) |
@codecalm i'm ready to test whenever the new version gets released on npm |
I'm testing new build and I'll release it as soon as possible. btw, new version will have number |
Added it to a random project I was working on. Before:
Adding these to my
After:
Looks fantastic, thank you @codecalm ! I believe I had to add the project to |
@codecalm, I was looking into the necessity of The magic is that |
To me @anthonyalayo it works without transpilePackages option (only put on modularizeimports), using nextjs 13.1.3. Doing a webpack analyzer in dev environment seems that only a few icons that I use are loading. |
@markitosgv its definitely working with only loading a few icons, but the no transpile part sounds odd. Are you running with |
I'm not sure what tricks @markitosgv did, but it's definitely not working without I'll file a follow up ticket @codecalm since it's definitely considered another feature. |
I'm using a monorepo with turborepo, I don't know if it's something with that |
@markitosgv most likely something there is performing the same process, you can reproduce it with a vanilla app like I did above. |
@anthonyalayo I've got a UI package with tabler icons dependency too, and for use this UI package in my project inside a monorepo I'm using transpilePackages option in next.config so I think is the reason that works for me |
@markitosgv that confirms it. Thanks! |
@markitosgv @anthonyalayo will there be any more changes needed in the tabler icons code to improve the process? |
I don't think you want to use kebab-case here. This worked for me: '@tabler/icons-react': {
transform: '@tabler/icons-react/dist/esm/icons/{{ camelCase member }}'
}, |
Currently, the React build produces a single
index.cjs.js
/index.esm.js
file including all icons. This is fine for some use cases but can cause bundle bloat / dev server slowness. It would be awesome if each icon was additionally put in its own file so they can be tree shaken effectively by a bundler. This would also allow something like Next.js to use themodularizeImports
feature to not bundle every single icon in both the development and production build.Example:
The text was updated successfully, but these errors were encountered: