簡體   English   中英

如何獲得適合 es 模塊導入的 lodash 自定義(簡化)構建?

[英]How to get a lodash custom (reduced) build suitable for es modules import?

我的意思是例如:

lodash include=each,find,filter,map,some,debounce,defer,delay,throttle,uniq,assign,extend,merge,omit,without,findIndex,compact,replace,groupBy,max,uniqueId

當我嘗試導入 es 模塊時,我收到如下警告:

打包並轉譯成功,但有警告:'this'關鍵字相當於ES模塊頂層的'undefined',已被重寫

是否有任何選項可以擁有相同的自定義(減少)構建,但適合在模塊中導入,然后像往常一樣通過'_'提供?

謝謝

您可以在本地文件中創建自己的聚合模塊...例如tools/lodash.js

export { 
  each, find, filter, map, some, debounce, defer, delay, throttle,
  uniq, assign, extend, merge, omit, without, findIndex, compact, 
  replace, groupBy, max, uniqueId 
} from 'lodash';

然后,當您想要這些工具時,您可以添加

import * as _ from './tools/lodash`;

如果您不喜歡import * as _語法,您可以在聚合模塊中直接導入,然后執行export default { each, find, ... }; . 這將允許您import _ from './tools/lodash'; .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM