这段时间用Vue2.0开发项目,每次打包都会用到新公共管理运行构建命令,但是每次部署时给后端发包都要手动活力压缩,这样一两次还行,但遇到项目板块测试和临时加急功能测试的时候,一天可能就要打包好多次,这就很烦了。所以索性在执行新公共管理运行构建命令时就直接打包成活力文件,方便省事!
1、插件装备
工具插件:filemanager-webpack-plugin,该插件可执行打包,复制,移动,删除文件以及新文件夹在建设之前及之后创建。
安装:
新公共管理安装文件管理器-网络包-插件-保存-开发或cnpm安装文件管理器-网络包-插件-保存-dev2,网络包配置
在项目根目录build/webpack.base.config.js中抬头变量声明区域添加
const FileManagerPlugin=require(' filemanager-web pack-plugin ')在根目录build/webpack.base.config.js内找到模块。导出。然后在插件内添加
新文件管理器登录({ onEnd: { delete: [)./dist/control-oper。zip ',],存档:[{ source : } ./dist ',destination: ' ./dist/control-oper。zip ' },] }})注:若插件不存在,则新建插件,插件为数组格式。
3、执行效果
配置完成后,重新执行新公共管理运行构建命令。执行完成后,在距离文件夹内(上面配置的目的地目录为距离文件夹),就可以看到压缩好的活力文件包了。
4、其他功能
module.exports={.插件:[新的FileManagerLugin({ ONed : { copy :[{ source : '/path/from ',destination : '/path/to '))},{source: '/path/**/* .js '、destination: '/path'}、{ source : '/path/from file。txt ',目标: '/文件路径。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/from file。txt ',目标: '/文件路径。txt ' }],delete: [ '/path/to/file.txt ','/path/to/directory/' ],mkdir:js ',destination : '/path/to . zip ' },{ source : '/path/from file。' txt ',destination : '/路径/to。zip ' },{ source : '/路径/来自文件。txt ',目的地: '/路径/to。zip '、format: 'tar'}、{ source : '/路径/来自文件。txt ',目标: '/路径/到.}总结
以上所述是小编给大家介绍的Vue webpack项目自动打包压缩成活力文件的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!