所以,我检查了我的遗留应用程序,有一些。
import _ from 'lodash';
一大堆...
import { method1, method2, method 3} from 'lodash';
所以,把他们都改成了。
import method1 from 'lodash/method1';
import method2 from 'lodash/method2';
然后是其他
import somFPmethod from 'lodash/fp/somFPmethod;
我想整个应用中总共有15个左右的独特方法,即isObject, merge , keys, last, flow。
我期待着我的应用捆绑(unminified)从11.8涨到11.5什么的......。
它上升了!
捆绑文件
BEFORE LODASH CHANGES:
Content-Length: 11813398
AFTER LODASH CHANGES:
Content-Length: 11991182
这怎么可能呢?
我使用的是: "lodash": "^4.17.15",
不管你是导入一个函数还是整个Lodash包,只要你使用Lodash NPM主包(npm install lodash
). 如果你想拥有一个缩小版的Lodash,并导入特定的函数,那么你需要使用 lodash-es
包代替。
https:/www.npmjs.compackagelodash-es
然后,你可以像这样导入特定的函数来代替。
import { isEqual, isNil } from 'lodash-es';
// Additional option: Allows you to alias the imports so you don't get naming conflicts.
import { isEqual as _isEqual, isNil as _isNil } from 'lodash-es';