How to Import a Single Lodash Function?

后端 未结 7 1783
無奈伤痛
無奈伤痛 2020-11-30 19:42

Using webpack, I\'m trying to import isEqual since lodash seems to be importing everything. I\'ve tried doing the following with no success:

imp         


        
7条回答
  •  我在风中等你
    2020-11-30 20:16

    With webpack 4 and lodash-es 4.17.7 and higher, this code works.

    import { isEqual } from 'lodash-es';
    

    This is because webpack 4 supports sideEffects flag and lodash-es 4.17.7 and higher includes the flag (which is set to false).

    Edit

    As of version 1.9.0, Parcel also supports "sideEffects": false, threrefore import { isEqual } from 'lodash-es'; is also tree shakable with Parcel.

提交回复
热议问题