如何获得适合 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',已被重写
是否有任何选项可以拥有相同的自定义(简化)构建,但适合在模块中导入,然后一如既往地通过 '_'
可用?
谢谢
您可以在本地文件中创建自己的 aggregating module...例如 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';
.
我的意思是例如:
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',已被重写
是否有任何选项可以拥有相同的自定义(简化)构建,但适合在模块中导入,然后一如既往地通过 '_'
可用?
谢谢
您可以在本地文件中创建自己的 aggregating module...例如 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';
.