Vue webpack 項目自動打包壓縮成zip文件的方法
這段時間用 Vue2.0 開發(fā)項目,每次打包都會用到 npm run build 命令,但是每次部署時給后端發(fā)包都要手動zip壓縮,這樣一兩次還行,但遇到項目板塊測試和臨時加急功能測試的時候,一天可能就要打包好多次,這就很煩了。所以索性在執(zhí)行 npm run build 命令時就直接打包成zip文件,方便省事!
1、插件裝備
webpack插件:filemanager-webpack-plugin,該插件可執(zhí)行打包,復(fù)制,移動,刪除文件以及新文件夾在build之前及之后創(chuàng)建。
安裝:
npm install filemanager-webpack-plugin --save-dev 或 cnpm install filemanager-webpack-plugin --save-dev
2、webpack配置
?、?在項目 根目錄 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 項目自動打包壓縮成zip文件的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
Vue Router實現(xiàn)多層嵌套路由的導(dǎo)航的詳細(xì)指南
在 Vue 應(yīng)用中,使用 Vue Router 可以輕松實現(xiàn)多層嵌套路由的導(dǎo)航,嵌套路由允許你創(chuàng)建一個多層次的 URL 結(jié)構(gòu),這在構(gòu)建具有復(fù)雜導(dǎo)航結(jié)構(gòu)的應(yīng)用程序時非常有用,需要的朋友可以參考下2024-10-10
使用element+vuedraggable實現(xiàn)圖片上傳拖拽排序
這篇文章主要為大家詳細(xì)介紹了使用element+vuedraggable實現(xiàn)圖片上傳拖拽排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04
詳解element-ui設(shè)置下拉選擇切換必填和非必填
這篇文章主要介紹了詳解element-ui設(shè)置下拉選擇切換必填和非必填,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
vue-treeselect(適配Vue3.2)及Element-plus的TreeSelect組件使用
這篇文章主要介紹了vue-treeselect(適配Vue3.2)及Element-plus的TreeSelect組件使用,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-05-05

