webpack將資源打成zip包
阿新 • • 發佈:2019-02-16
webpack外掛:filemanager-webpack-plugin
該外掛允許你複製,打包,移動,刪除檔案及資料夾在build之前及之後。
安裝:
npm install filemanager-webpack-plugin --save-dev
資源打zip包 Webpack.config.js:
const FileManagerPlugin = require('filemanager-webpack-plugin'); new FileManagerPlugin({ onEnd: { mkdir: ['./zip'], archive: [ { source: './dist', destination: './zip/test.zip' }, ] } })
其他功能(移動,打包,複製)Webpack.config.js::
const FileManagerPlugin = require('filemanager-webpack-plugin'); 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 } } } ] } }) ], ... }