1. 安装filemanager-webpack-plugin包
npm install filemanager-webpack-plugin@2.0.5 -D
2. 在package.json里修改版本号
例如:修改version为1.0.0
{ "name": "my-app", "version": "1.0.0", "description": "A vue template with Element UI & axios & iconfont & permission control", "author": "", ... }
3. 在vue.config.js添加如下代码
const config = require('./package.json') const version = `${config.version}` const FileManagerPlugin = require('filemanager-webpack-plugin') module.exports = { ... configureWebpack: { // 将打包后的dist文件自动压缩成dist-1.0.0.zip包 plugins: [ new FileManagerPlugin({ onEnd: { mkdir: ['./dist'], archive: [{ source: `./dist`, destination: `./dist-${version}.zip` }] } }) ] } }
配置完成后,打包时会同时生成dist打包文件夹和dist-1.0.0.zip压缩包
项目根目录终端输入打包命令
npm run build