Vue webpack 项目自动打包压缩成zip文件的方法
前端  /  管理员 发布于 4年前   758
这段时间用 Vue2.0 开发项目,每次打包都会用到 npm run build
命令,但是每次部署时给后端发包都要手动zip压缩,这样一两次还行,但遇到项目板块测试和临时加急功能测试的时候,一天可能就要打包好多次,这就很烦了。所以索性在执行 npm run build
命令时就直接打包成zip文件,方便省事!
1、插件装备
webpack插件:filemanager-webpack-plugin
,该插件可执行打包,复制,移动,删除文件以及新文件夹在build之前及之后创建。
安装:
npm install filemanager-webpack-plugin --save-dev或cnpm install filemanager-webpack-plugin --save-dev
2、webpack配置
① 在项目 根目录 build/webpack.base.config.js
中 抬头变量声明区域添加
const FileManagerPlugin = require('filemanager-webpack-plugin')
② 在根目录 build/webpack.base.config.js
内找到 module.exports。 然后在plugins内添加
new FileManagerPlugin({ onEnd: { delete: [ './dist/control-operate.zip', ], archive: [ {source: './dist', destination: './dist/control-operate.zip'}, ] }})
注:若 plugins不存在,则新建plugins,plugins为数组格式。
3、执行效果
配置完成后,重新执行 npm run build
命令。执行完成后,在dist文件夹内(上面配置的目的地目录为 dist文件夹),就可以看到压缩好的zip文件包了。
4、其他功能
module.exports = { ...... plugins: [ new FileManagerPlugin({ onEnd: { copy: [ {source: '/path/from', destination: '/path/to'}, {source: '/path/**/*.js', destination: '/path'}, {source: '/path/fromfile.txt', destination: '/path/tofile.txt'}, {source: '/path/**/*.{html,js}', destination: '/path/to'}, {source: '/path/{file1,file2}.js', destination: '/path/to'}, {source: '/path/file-[hash].js', destination: '/path/to'} ], move: [ {source: '/path/from', destination: '/path/to'}, {source: '/path/fromfile.txt', destination: '/path/tofile.txt'} ], delete: [ '/path/to/file.txt', '/path/to/directory/' ], mkdir: [ '/path/to/directory/', '/another/directory/' ], archive: [ {source: '/path/from', destination: '/path/to.zip'}, {source: '/path/**/*.js', destination: '/path/to.zip'}, {source: '/path/fromfile.txt', destination: '/path/to.zip'}, {source: '/path/fromfile.txt', destination: '/path/to.zip', format: 'tar'}, { source: '/path/fromfile.txt', destination: '/path/to.tar.gz', format: 'tar', options: { gzip: true, gzipOptions: { level: 1 } } } ] } }) ], ......}
总结
以上所述是小编给大家介绍的Vue webpack 项目自动打包压缩成zip文件的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号