react-feather: Tree-shaking seems to be broken
Running webpack bundle analyzer, I am seeing every icon being included in my minified bundles:

Not sure if I am doing something wrong of if there is a problem in the package.
babelrc settings:
{
"presets": [
["env", {
"loose": true,
"modules": false
}], "react"
],
plugins: [
'syntax-dynamic-import',
'transform-object-rest-spread',
'transform-class-properties'
]
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 15
- Comments: 24 (3 by maintainers)
Commits related to this issue
- feat: add tree-shaking supportive fix #6 — committed to lili21/react-feather by lili21 6 years ago
- Switch from react-feather to react-icons. Bundle size drops ~250kb, but now our icons are the wrong size... Hopefully this gets fixed so we can revert: https://github.com/feathericons/react-feather/... — committed to mytakedotorg/mtdo by nedtwigg 4 years ago
@nedtwigg You need to change the following lines in
tsconfig.json:Check out the size before
409054 Band after27987 B.Basically, with
commonjsyou are tellingtypescriptto transpile ES Modules into CommonJSrequire/exportssyntax. CommonJS is notoriously hard to tree shake due to its dynamic nature, and most bundlers doesn’t even try. If you setesnexthowever, this will leaveimport/exportsyntax intact so that webpack can take care of module resolution and tree shaking.Same problem, but i use TypeScript without Babel.
Fast fix for reduce bundle size - use full path, example:
import Download from 'react-feather/dist/icons/download';Version 2.0.1 is out, with all the latest icons and support for tree-shaking.
@carmelopullara I’m using
2.0.8and I still seem to have the issue.I’m using ES imports (reexports, not full paths) within a CRA app.
Yo guys,
Help is here:
["import", { "libraryName": "react-feather", "libraryDirectory": "dist/icons", "camel2DashComponentName": false }],Profit!
@carmelopullara I don’t see the tree-shaking working properly with es imports:
All library ends up in the bundle. What’s the intended way to use the lib?
@cichelero Would it help if the project added a
"sideEffects": falseto the package.json file, according to the link you posted?