Tree-shaking seems to be broken
See original GitHub issueRunning 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'
]
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:24 (3 by maintainers)
Top Results From Across the Web
Tree-shaking seems to be broken in spack #3951 - GitHub
I'm trying to set up my project with swc and spack, but I can't get tree shaking to work. Input code. // src/lib.ts...
Read more >Tree shaking and code splitting in webpack - LogRocket Blog
Tree shaking, also known as dead code elimination, is the practice of removing unused code in your production build. It's important to ship...
Read more >Tree-Shaking: A Reference Guide - Smashing Magazine
Simply put, tree-shaking means removing unreachable code (also known as dead code) from a bundle. As Webpack version 3's documentation states: “ ...
Read more >Tree-shaking in real world: what could go wrong? - Medium
Tree shaking is not as easy as it seems; You can only use tree-shaking if you're using ES modules; Babel doesn't produce tree-shakable ......
Read more >Reduce JavaScript payloads with tree shaking - web.dev
Tree shaking is a form of dead code elimination. The term was popularized by Rollup, but the concept of dead code elimination has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nedtwigg You need to change the following lines in
tsconfig.json
:Check out the size before
409054 B
and after27987 B
.Basically, with
commonjs
you are tellingtypescript
to transpile ES Modules into CommonJSrequire
/exports
syntax. CommonJS is notoriously hard to tree shake due to its dynamic nature, and most bundlers doesn’t even try. If you setesnext
however, this will leaveimport
/export
syntax 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';