Materialdesign: Using icons from @mdi/js imports entire package

Created on 6 Nov 2019  路  18Comments  路  Source: Templarian/MaterialDesign

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?

Question

All 18 comments

Does it do this even for a production build?

Might be how your project is configured.

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 "module":"commonjs". The module type needs to be es6 for the tree shaking to work. Thanks

I'll add this to the documentation after work. Needs a troubleshooting section.

If you're using @font-face to import the Web font from the online copy, and you know the Unicode code point of the icons you need, you can use the property unicode-range to only import the necessary glyphs. Google Fonts does this to specify the character set you need (e.g. Latin Extended, Devanagari, etc.).
Documentation of unicode-range

@JapanYoshi This is for the @mdi/js package. I think you might be replying to the wrong issue?

I'm using "module": "es2020", and I'm still observing the same issue. Just importing and using one icon bumps up the build size by 2.6mb. Going down to es6 is not an option for my at this point.

@guyyst Can you give more details about your setup? Webpack / Rollup / TS etc?

I'm using "module": "es2020", and I'm still observing the same issue. Just importing and using one icon bumps up the build size by 2.6mb. Going down to es6 is not an option for my at this point.

@guyyst try this and see if it helps "module": "es6", "moduleResolution": "node",

I spun up a new angular app on es2020 with nothing but @mdi/js installed and the tree shaking is working properly. I must have misconfigured something in my other project since the package is working just fine 馃憤

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 npm run build ?

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? import { mdiAccount } from '@mdi/js'; ?

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.
I created a new create-react-app from scratch, then installed @mdi/js et @mdi/react and tried importing a few icons. It seems that everything is working fine. With 2 icons imported, @mdi/js size is only 452B. I'll try to investigate further more on my main project

@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 @mdi/js inside my bundle when I analyze with https://www.npmjs.com/package/source-map-explorer

@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 @mdi/js inside my bundle when I analyze with https://www.npmjs.com/package/source-map-explorer

Can you share your setup?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alvaroc1 picture alvaroc1  路  3Comments

xaviergonz picture xaviergonz  路  3Comments

vishnu1991 picture vishnu1991  路  3Comments

Kanga-Who picture Kanga-Who  路  3Comments

bckp1993 picture bckp1993  路  3Comments