应用场景
我们经常需要在执行npm run build之后把生成的static和index.html打包压缩成一个压缩包发送给后端进行项目部署,每次都需要手动操作太过繁琐,so 有需求就要找方法…
filemanager-webpack-plugin
- 安装
npm i filemanager-webpack-plugin
插件配置
在build/webpack.base.config.js里加上如下代码
const FileManagerWebpackPlugin = require('filemanager-webpack-plugin') new FileManagerWebpackPlugin ({ // 需要在 plugins 数组里添加 onEnd: { delete: [ './dist/bhg-member-portal.zip', // 删除之前已经存在的压缩包 ], archive: [ {source: './dist', destination: './dist/bhg-member-portal.zip'}, ] } })
zip-webpack-plugin
- GitHub地址
- 安装
npm install --save-dev zip-webpack-plugin
- webpack.base.conf中进行配置
const ZipWebpackPlugin = require('zip-webpack-plugin')
new ZipWebpackPlugin ({
path:path.join(__dirname,'../dist'),
filename: 'bhg-member-portal.zip'
})