简体   繁体   English

如何以正确的方式在webpack模块中使用库

[英]How to use libraries in webpack modules the right way

Whats best practice for using libs like lodash in modules bundled by webpack? 什么是在webpack捆绑的模块中使用像lodash这样的库的最佳实践?

1. require it to a global variable 1.要求它为全局变量

window._ = require('lodash');

2. webpack conf 2. webpack conf

new webpack.ProvidePlugin({ _: 'lodash' });

3. Require it in a module if I want to use lodash in that module like 3.如果我想在该模块中使用lodash,请在模块中使用它

let _ = require('lodash');

or 要么

import _ from lodash;

4. import only the functions I want to use in the current module from lodash like 4.从lodash中仅导入我想要在当前模块中使用的函数

import { find, map } from 'lodash';
import { find, map } from 'lodash';

应该用来支持三个摇晃

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM