'use strict';
const path = require('path')
// 是否為生產(chǎn)環(huán)境
const isProduction = process.env.NODE_ENV !== 'development';
// gzip壓縮
const CompressionWebpackPlugin = require('compression-webpack-plugin')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: '',
assetsDir: 'static',
productionSourceMap: true,
devServer: {
proxy: {
'/xxx': { //項目名
target: '',// 接口的域名
secure: false, // 如果是https接口贫堰,需要配置這個參數(shù)為true
changeOrigin: true,// 如果接口跨域,需要進行這個參數(shù)配置
},
} // 代理轉(zhuǎn)發(fā)配置,用于調(diào)試環(huán)境
},
lintOnSave: false, //去除eslint
configureWebpack: config => {
// 生產(chǎn)環(huán)境相關(guān)配置
if (isProduction) {
//gzip壓縮
const productionGzipExtensions = ['html', 'js', 'css']
config.plugins.push(
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' + productionGzipExtensions.join('|') + ')$'
),
threshold: 10240, // 只有大小大于該值的資源會被處理 10240
minRatio: 0.8, // 只有壓縮率小于這個值的資源才會被處理
deleteOriginalAssets: false // 刪除原文件
})
)
}
},
chainWebpack(config) {
// it can improve the speed of the first screen, it is recommended to turn on preload
// config.plugins.delete('preload')
// when there are many pages, it will cause too many meaningless requests
config.plugin('preload').tap(() => [
{
rel: 'preload',
// to ignore runtime.js
// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
include: 'initial'
}
])
config.plugins.delete('prefetch')
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
// set preserveWhitespace
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/
}])
.end()
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
})
config.optimization.runtimeChunk('single')
}
)
}
};
vue.config.js配置
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來澎灸,“玉大人院塞,你說我怎么就攤上這事院水⌒渤觯” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長巩梢。 經(jīng)常有香客問我,道長艺玲,這世上最難降的妖魔是什么括蝠? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮饭聚,結(jié)果婚禮上忌警,老公的妹妹穿的比我還像新娘。我一直安慰自己秒梳,他們只是感情好法绵,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著酪碘,像睡著了一般朋譬。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上兴垦,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼鲤氢!你這毒婦竟也來了搀擂?” 一聲冷哼從身側(cè)響起拐纱,我...
- 正文 年R本政府宣布附迷,位于F島的核電站惧互,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏喇伯。R本人自食惡果不足惜喊儡,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望稻据。 院中可真熱鬧艾猜,春花似錦、人聲如沸捻悯。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽今缚。三九已至算柳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間荚斯,已是汗流浹背埠居。 一陣腳步聲響...