Vue webpack 項(xiàng)目自動(dòng)打包壓縮成zip文件的方法
這段時(shí)間用 Vue2.0 開發(fā)項(xiàng)目,每次打包都會(huì)用到 npm run build 命令,但是每次部署時(shí)給后端發(fā)包都要手動(dòng)zip壓縮,這樣一兩次還行,但遇到項(xiàng)目板塊測(cè)試和臨時(shí)加急功能測(cè)試的時(shí)候,一天可能就要打包好多次,這就很煩了。所以索性在執(zhí)行 npm run build 命令時(shí)就直接打包成zip文件,方便省事!
1、插件裝備
webpack插件:filemanager-webpack-plugin,該插件可執(zhí)行打包,復(fù)制,移動(dòng),刪除文件以及新文件夾在build之前及之后創(chuàng)建。
安裝:
npm install filemanager-webpack-plugin --save-dev 或 cnpm install filemanager-webpack-plugin --save-dev
2、webpack配置
?、?在項(xiàng)目 根目錄 build/webpack.base.config.js 中 抬頭變量聲明區(qū)域添加
const FileManagerPlugin = require('filemanager-webpack-plugin')
?、?在根目錄 build/webpack.base.config.js 內(nèi)找到 module.exports。 然后在plugins內(nèi)添加
new FileManagerPlugin({
onEnd: {
delete: [
'./dist/control-operate.zip',
],
archive: [
{source: './dist', destination: './dist/control-operate.zip'},
]
}
})
注:若 plugins不存在,則新建plugins,plugins為數(shù)組格式。

3、執(zhí)行效果
配置完成后,重新執(zhí)行 npm run build 命令。執(zhí)行完成后,在dist文件夾內(nèi)(上面配置的目的地目錄為 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
}
}
}
]
}
})
],
......
}
總結(jié)
以上所述是小編給大家介紹的Vue webpack 項(xiàng)目自動(dòng)打包壓縮成zip文件的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
Vue Router實(shí)現(xiàn)多層嵌套路由的導(dǎo)航的詳細(xì)指南
在 Vue 應(yīng)用中,使用 Vue Router 可以輕松實(shí)現(xiàn)多層嵌套路由的導(dǎo)航,嵌套路由允許你創(chuàng)建一個(gè)多層次的 URL 結(jié)構(gòu),這在構(gòu)建具有復(fù)雜導(dǎo)航結(jié)構(gòu)的應(yīng)用程序時(shí)非常有用,需要的朋友可以參考下2024-10-10
使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序
這篇文章主要為大家詳細(xì)介紹了使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
詳解element-ui設(shè)置下拉選擇切換必填和非必填
這篇文章主要介紹了詳解element-ui設(shè)置下拉選擇切換必填和非必填,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
Vue后臺(tái)實(shí)現(xiàn)點(diǎn)擊圖片放大功能的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Vue實(shí)現(xiàn)點(diǎn)擊圖片放大功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下2022-12-12
vue-treeselect(適配Vue3.2)及Element-plus的TreeSelect組件使用
這篇文章主要介紹了vue-treeselect(適配Vue3.2)及Element-plus的TreeSelect組件使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05

