Vue  webpack項(xiàng)目自動(dòng)打包壓縮成zip文件的方法

這段時(shí)間用 Vue2.0 開(kāi)發(fā)項(xiàng)目,每次打包都會(huì)用到 npm run build 命令,但是每次部署時(shí)給后端發(fā)包都要手動(dòng)zip壓縮,這樣一兩次還行,但遇到項(xiàng)目板塊測(cè)試和臨時(shí)加急功能測(cè)試的時(shí)候,一天可能就要打包好多次,這就很煩了。所以索性在執(zhí)行 npm run build 命令時(shí)就直接打包成zip文件,方便省事!

十余年的肇慶網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整肇慶建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“肇慶網(wǎng)站設(shè)計(jì)”,“肇慶網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

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ù)組格式。

Vue  webpack 項(xiàng)目自動(dòng)打包壓縮成zip文件的方法

3、執(zhí)行效果

配置完成后,重新執(zhí)行 npm run build 命令。執(zhí)行完成后,在dist文件夾內(nèi)(上面配置的目的地目錄為 dist文件夾),就可以看到壓縮好的zip文件包了。

Vue  webpack 項(xiàng)目自動(dòng)打包壓縮成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ì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

新聞標(biāo)題:Vue  webpack項(xiàng)目自動(dòng)打包壓縮成zip文件的方法
網(wǎng)站網(wǎng)址:http://muchs.cn/article12/gdcpdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、響應(yīng)式網(wǎng)站、域名注冊(cè)、企業(yè)網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)公司微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)