question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree-shaking seems to be broken

See original GitHub issue

Running webpack bundle analyzer, I am seeing every icon being included in my minified bundles: screen shot 2017-11-14 at 8 11 56 am

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:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
alex996commented, Sep 12, 2020

@nedtwigg You need to change the following lines in tsconfig.json:

-"module": "commonjs",
+"module": "esnext",
+"moduleResolution": "node",

Check out the size before 409054 B and after 27987 B.

Basically, with commonjs you are telling typescript to transpile ES Modules into CommonJS require/exports syntax. CommonJS is notoriously hard to tree shake due to its dynamic nature, and most bundlers doesn’t even try. If you set esnext however, this will leave import/export syntax intact so that webpack can take care of module resolution and tree shaking.

4reactions
SuperOleg39commented, Nov 22, 2017

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';

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found