-
-
Notifications
You must be signed in to change notification settings - Fork 731
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
Using icons from @mdi/js imports entire package #4576
Comments
Does it do this even for a production build? Might be how your project is configured. |
I found a solution, the problem was in the configuration in my tscofig I had |
I'll add this to the documentation after work. Needs a troubleshooting section. |
Added to the docs for webpack. https://dev.materialdesignicons.com/getting-started/webpack |
@JapanYoshi This is for the |
I'm using |
@guyyst Can you give more details about your setup? Webpack / Rollup / TS etc? |
@guyyst try this and see if it helps |
I spun up a new angular app on |
Hi I'm using create-react-app and @mdi/js. I'm only using a few icons from @mdi/js but the bundle size is 1.76MB larger (33% of total bundle size) even for production build. So I assume tree shaking is not working. I do not have access to webpack config (because I'm using create-react-app). Have you ever encountered this issue ? |
@emileNetter Seeing the same thing with |
Sorry, too early, can't read you already said that. |
I use https://www.npmjs.com/package/source-map-explorer to analyze bundle size (after npm run build) |
@emileNetter You're importing only single icons right? Not really sure what could be happening. It should just work as that uses webpack. |
Yes I'm only importing single icons like in your example. |
@emileNetter I'm running into this problem as well now. Any chance you found the cause? I've got 29 icons imported and seeing 2.04 MB for |
Can you share your setup? |
@Immugio can you tell me which version of mdi/js you are using |
@Templarian I'm running into this same issue. I've created a stripped down repo here: https://github.com/caseyjhol/minimal-webpack-mdi. Clone the repo, run |
I figured out my issue - tree shaking doesn't working properly with esbuilder-loader (privatenumber/esbuild-loader#178). Switching back to Terser seems to have solved my problem. |
Seeing the same behavior with this
I get tree-shaking for other modules, but not for |
I'm having the same issue for a Vue.js v2 project using typescript. Dependencies: The issue occurs when building as web component using the command Altering the target version from |
Hi guys, same here 😔 |
Hello, same issue. package.json: |
@Templarian you probably want to reopen this, it's kind of a big deal. Importing like this: import Icon from '@mdi/react';
import {
...
mdiEarth,
} from '@mdi/js'; Update: Yep, the problem was on my side. Treeshaking was not working. |
If you feel that this is still an issue, please provide us with a barebones git repository proving the issue. Through extensive testing, I have personally never been able to reproduce this issue under normal, default circumstances. Depending on your bundler/settings, while in development mode tree-shaking may not occur. There are also other settings, plugins, etc. that might disable or hinder tree-shaking. Be sure you're checking your production bundles. Sidenote, I'm literally working on the new Pictogrammers/MDI website as we speak and I just double-checked the production output and only the icons being included are bundled, further confirming a likely configuration issue on your end. |
@mririgoyen , is treeshaking possible in any target besides es6? I’m not able to get tree shaking working for my webpack 5 project and es6 is not an option for me. |
We had the same issue, the reason is the invalid / missing exports. Causing webpack to import the commonjs version that gets not tree-shaken. |
In our case, the reason for tree-shaking not working of the Sry for replying to a closed issue, just wanted to remind others who might encounter a similar problem. |
I'm using a few icons from the @mdi/js. The package is added as devDependency and the import is done in this way:
import { mdiFlipHorizontal, .. } from "@mdi/js";
After building the project with webpack this result in approx. 1.6MB extra size added to the output bundle. Is there any way to just import a single icon?
The text was updated successfully, but these errors were encountered: