需求场景:每次项目打包都需要手动将
dist文件夹
,压缩为dist.zip
比较繁琐
功能实现:每次运行npm run build
自动生成dist.zip
首先下载插件
npm install filemanager-webpack-plugin --save-dev
然后在项目根目录找到:vue.config.js
文件
const { defineConfig } = require('@vue/cli-service')
// 插件地址: https://www.npmjs.com/package/filemanager-webpack-plugin
const FileManagerPlugin = require('filemanager-webpack-plugin')
const path = require('path')
module.exports = defineConfig({
lintOnSave: false,
transpileDependencies: true,
// 配置插件
configureWebpack: {
plugins: [
new FileManagerPlugin({
events: {
onEnd: {
delete: ['./dist.zip'],
archive: [{
source: path.join(__dirname, './dist'),
destination: path.join(__dirname, './dist.zip')
}]
}
}
})
]
}
})
最后在终端运行:npm run build
,运行结束在项目根目录自动生成 dist.zip
压缩包