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.

Any way to reduce bundle size after tree shaking?

See original GitHub issue

After correctly using tree shaking (I’m using about 20 icons, no layers) and setting:

    addCss: false,
    useLayers: false,
    useLayersText: false,

in module config, my top size in bundle is fontawesome-svg-core which includes some unuseful code for my needs and it seems there’s no way to limit its size. Am I missing something? thanks image

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
alexcrooxcommented, Jan 29, 2021

Note you can use babel-plugin-transform-imports lib to this automatically for you on build:

import { faApple } from '@fortawesome/free-brands-svg-icons'

build: {
  babel: {
    plugins: [
      'lodash',
      [
        'transform-imports',
        {
          /* eslint-disable no-template-curly-in-string */
          '@fortawesome/pro-regular-svg-icons': {
            transform: '@fortawesome/pro-regular-svg-icons/${member}',
            skipDefaultConversion: true
          },
          '@fortawesome/pro-solid-svg-icons': {
            transform: '@fortawesome/pro-solid-svg-icons/${member}',
            skipDefaultConversion: true
          },
          '@fortawesome/pro-light-svg-icons': {
            transform: '@fortawesome/pro-light-svg-icons/${member}',
            skipDefaultConversion: true
          },
          '@fortawesome/free-brands-svg-icons': {
            transform: '@fortawesome/free-brands-svg-icons/${member}',
            skipDefaultConversion: true
          },
          lodash: {
            transform: 'lodash/${member}',
            preventFullImport: true
          }
          /* eslint-enable no-template-curly-in-string */
        }
      ]
    ]
  }
}

Edit: my extracted example above includes handling of tree shaking for lodash so you can just remove that if you don’t use it

0reactions
P4sca1commented, Nov 9, 2020

Tree shaking is disabled in dev, so it imports the whole set in development. I suggest changing the code to do one import per icon (adding the icon name at the end of the import path) to only import icons that are used. This would improve page load time in dev which is especially relevant when not accessing the page via localost but via a proxy. In production it is more performant to do a single import as unused icons are tree shaked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reduce JavaScript payloads with tree shaking - web.dev
Tree shaking addresses this by taking advantage of how static import statements pull in ... bundle isn't bad, but it should be noted...
Read more >
Optimize your bundle size by eliminating dead code / tree ...
Today, I want to talk about a very effective method to optimize your bundle size called Tree Shaking. Traditionally, we install a module...
Read more >
Reduce bundle size / improve tree shaking #2843 - GitHub
Reduce bundle size / improve tree shaking. ... Reanimated's bundle size is currently massive, and it doesn't have any optimizations for tree shaking....
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 >
5 Methods to Reduce JavaScript Bundle Size - Bits and Pieces
5 Methods to Reduce JavaScript Bundle Size · 1. Code Splitting with Webpack · 2. Using Webpack Plugins for Tree Shaking · 3....
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