// 详细配置请参考https://cli.vuejs.org/zh/config/#vue-config-js
|
// const outputDir = process.env.VUE_APP_CONTEXT_PATH.substring(1, process.env.VUE_APP_CONTEXT_PATH.length - 1)
|
// const outputDir = process.env.VUE_APP_CONTEXT_PATH.substring(1, process.env.VUE_APP_CONTEXT_PATH.length)
|
const CompressionPlugin = require('compression-webpack-plugin')
|
module.exports = {
|
publicPath: './',
|
outputDir: process.env.VUE_APP_CONTEXT_NAME,
|
assetsDir: 'static',
|
lintOnSave: false,
|
devServer: {
|
host: '0.0.0.0',
|
port: 10086,
|
proxy: {
|
[process.env.VUE_APP_API_PREFIX]: {
|
target: process.env.VUE_APP_API,
|
changeOrigin: true,
|
pathRewrite: {
|
[`^${[process.env.VUE_APP_API_PREFIX]}`]: ''
|
}
|
}
|
}
|
},
|
configureWebpack: config => {
|
// if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') {
|
return {
|
plugins: [
|
new CompressionPlugin({
|
algorithm: 'gzip', // 使用gzip压缩
|
test: /\.(js|css|html)$/, // 匹配文件类型
|
threshold: 10240, // 只处理比这个值大的资源。值是字节,10240字节=10KB
|
minRatio: 0.8 // 压缩比率,只有压缩率小于这个值的资源才会被处理
|
})
|
],
|
optimization: {
|
runtimeChunk: 'single',
|
splitChunks: {
|
chunks: 'all',
|
maxInitialRequests: Infinity,
|
minSize: 20000,
|
cacheGroups: {
|
vendors: {
|
test: /[\\/]node_modules[\\/]/, // 使用正则匹配node_modules中引入的模块
|
priority: -10, // 优先级值越大优先级越高,默认-10,不用修改
|
name(module) {
|
// 设定分包以后的文件模块名字,按照包名字替换拼接一下
|
|
if (!module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)) return;
|
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
return `npm.${packageName.replace('@', '')}`;
|
}
|
}
|
}
|
}
|
}
|
}
|
// }
|
}
|
}
|