How to decrease prod bundle size?

后端 未结 14 1434
Happy的楠姐
Happy的楠姐 2020-11-28 01:31

I have a simple app, initialized by angular-cli.

It display some pages relative to 3 routes. I have 3 components. On one of this page I use lodash

14条回答
  •  猫巷女王i
    2020-11-28 02:00

    Lodash can contribute a bug chunk of code to your bundle depending on how you import from it. For example:

    // includes the entire package (very large)
    import * as _ from 'lodash';
    
    // depending on your buildchain, may still include the entire package
    import { flatten } from 'lodash';
    
    // imports only the code needed for `flatten`
    import flatten from 'lodash-es/flatten'
    

    Personally I still wanted smaller footprints from my utility functions. E.g. flatten can contribute up to 1.2K to your bundle, after minimization. So I've been building up a collection of simplified lodash functions. My implementation of flatten contributes around 50 bytes. You can check it out here to see if it works for you: https://github.com/simontonsoftware/micro-dash

提交回复
热议问题