plugin-enable 打包多个库
时间: 2023-05-09 16:01:58 浏览: 57
plugin-enable 是一个用于打包多个库的插件。在使用webpack进行打包时,我们可能需要将多个相关的库打包成一个单独的库,在这种情况下,使用plugin-enable插件可以简化我们的打包方式。
使用plugin-enable插件,我们需要先进行配置。在webpack的配置文件中,我们需要定义我们的入口文件和出口文件,同时使用plugin-enable插件来制定需要打包的模块名称。比如,我们可以指定打包jquery和underscore这两个库,我们就可以在配置文件中这样写:
```
const path = require('path');
const PluginEnable = require('plugin-enable-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-library.js',
library: 'MyLibrary',
libraryTarget: 'umd',
},
plugins: [
new PluginEnable({
modules: ['jquery', 'underscore']
})
]
};
```
在上面的配置中,我们指定了入口文件为index.js,出口文件为dist/my-library.js,同时使用了PluginEnable来指定需要打包的库为jquery和underscore。最终,我们的打包结果会将这两个库合并到my-library.js中。
通过使用plugin-enable插件,我们可以方便地打包多个相关的库,简化我们的打包流程,提高了我们的效率。