tips注意版本--不然會報錯
npm install --save-dev compression-webpack-plugin@1.1.11
複製代碼
productionGzip: true,
productionGzipExtensions: ['js', 'css'],
複製代碼
該插件可執行打包,複製,移動,刪除文件以及新文件夾在build以前及以後建立。
cnpm install filemanager-webpack-plugin --save-dev
複製代碼
webpack配置1. 通常在項目 根目錄 build/webpack.base.config.js 中 擡頭變量聲明區域添加
tips 聲明看我的配置
const FileManagerPlugin = require('filemanager-webpack-plugin')
2.在根目錄 build/webpack.base.config.js 內找到 module.exports。而後在plugins內添加
(不光支持打包成zip 還能夠改爲.gz 等主流壓縮形式---存放目錄可配置--)
new FileManagerPlugin({
onEnd: {
delete: [
'./dist/control-operate.zip',
],
archive: [
{source: './dist', destination: './dist/control-operate.zip'},
]
}
})
tips: 若 plugins不存在,則新建plugins,plugins爲數組格式。
plugins: []
配置完執行打包命令就ok了
複製代碼
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
}
}
}
]
}
})
]
}
複製代碼