html 5 压缩zip,使用node执行命令, 使前端项目打包后自动压缩成zip包. 省时又省力??...

该博客介绍了如何在VueCLI2和3的项目中,通过修改配置文件,实现在Webpack打包完成后自动执行命令,将打包的文件压缩成ZIP包。在VueCLI2中,直接在build/build.js的回调函数中添加执行WinRAR命令;而在VueCLI3中,需在vue.config.js的configureWebpack中添加插件实现相同功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在 vue cli2 的项目中 找到 build/build.js

在webpack(webpackConfig, cb) 的 回调函数cb中

添加

const exec = require('child_process').exec

exec('cd .\\dist && del dist.zip', function(error) {

if (error) {

console.log(error)

}

// D:\\program\\WinRAR\\WinRAR.exe 需要改为你电脑上WinRAR的安装目录

exec('cd .\\dist && D:\\program\\WinRAR\\WinRAR.exe a -r dist.zip .\\*.*', function(error) {

if (error) {

console.log(error)

}

})

})

就会在webpack打包结束后将我们的打包出来的文件打包成zip包

vue cli3 中要麻烦些

需要在 vue.config.js 中找到

configureWebpack

在这个选项下添加插件

configureWebpack: config => {

if (process.env.NODE_ENV === 'production') {

config.plugins.push({

apply: (compiler) => {

compiler.hooks.done.tap(pluginName, compilation => {

// 这里执行我们的代码

const exec = require('child_process').exec

exec('cd .\\dist && del dist.zip', function(error) {

if (error) {

console.log(error)

}

// D:\\program\\WinRAR\\WinRAR.exe 需要改为你电脑上WinRAR的安装目录

exec('cd .\\dist && D:\\program\\WinRAR\\WinRAR.exe a -r dist.zip .\\*.*', function(error) {

if (error) {

console.log(error)

}

})

})

});

}

})

} else {

// 为开发环境修改配置...

}

b739ec46bb5c46d9c0aa4ce35ba1ea56.png

关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。

本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。

[使用node执行命令, 使前端项目打包后自动压缩成zip包. 省时又省力??]http://www.zyiz.net/tech/detail-119985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值