-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
130 lines (120 loc) · 3.68 KB
/
vue.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 引入gzip压缩插件
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const ThemeColorReplacer = require('webpack-theme-color-replacer')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const {getThemeColors, modifyVars} = require('./src/helpers/themeUtil')
const {resolveCss} = require('./src/helpers/theme-color-replacer-extend')
const { baseAlias, devServer } = require('./config')
module.exports = {
publicPath: `${baseAlias}/`,
lintOnSave: false,
productionSourceMap: false,
devServer: devServer,
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [path.resolve(__dirname, "./src/theme/theme.less")],
}
},
css: {
loaderOptions: {
less: {
lessOptions: {
modifyVars: modifyVars(),
javascriptEnabled: true
}
}
}
},
configureWebpack: config => {
config.plugins.push(
new ThemeColorReplacer({
fileName: 'css/theme-colors-[contenthash:8].css',
matchColors: getThemeColors(),
resolveCss
})
)
if (process.env.NODE_ENV === 'production') {
// 分析
config.plugins.push(new BundleAnalyzerPlugin())
config.plugins.push(
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log'] // 移除console
}
}
})
)
}
},
chainWebpack (config) {
// 禁用prefetch和preload,在router.jszhong1通过webpack的内联注释手动选定要提前获取的代码区块
// https://cli.vuejs.org/zh/guide/html-and-static-assets.html#preload
config.plugins.delete('preload')
config.plugins.delete('prefetch')
// 开启热更新
//config.resolve.symlinks(true)
config.externals = {
'echarts': 'echarts',
'ant-design-vue': 'ant-design-vue'
}
// 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.devtool('cheap-source-map')
)
config.when(process.env.NODE_ENV !== 'development', config => {
config.plugin('optimize-css')
.tap(args => {
args[0].cssnanoOptions.preset[1].colormin = false
return args
})
config
.plugin("compressionPlugin")
.use(CompressionPlugin)
.tap(() => [
{
test: /\.js$|\.html$|\.css/, //匹配文件名
threshold: 102400, //超过10k进行压缩
deleteOriginalAssets: false //是否删除源文件
}
]);
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
//公用模块抽离
common: {
chunks: 'initial',
minSize: 0, //大于0个字节
minChunks: 2, //抽离公共代码时,这个代码块最小被引用的次数
},
//第三方库抽离
vendor: {
priority: 1, //权重
test: /node_modules/,
chunks: 'initial',
minSize: 0, //大于0个字节
minChunks: 2, //在分割之前,这个代码块最小应该被引用的次数
}
}
})
config.optimization.runtimeChunk('single')
})
}
}