-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvue.config.js
91 lines (89 loc) · 2.32 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
/* 配置文件 */
const path = require('path')
const WebpackBar = require('webpackbar')
const TerserPlugin = require('terser-webpack-plugin')
const {
publicPath,
assetsDir,
outputDir,
lintOnSave,
productionSourceMap,
title,
devServer
} = require('./src/config/vue.custom.config.ts')
module.exports = {
publicPath,
outputDir,
assetsDir,
lintOnSave,
productionSourceMap,
devServer,
pluginOptions: {
'style-resources-loader': {
preProcessor: 'scss',
patterns: [
path.resolve(__dirname, 'src/styles/variables.scss'),
path.resolve(__dirname, 'src/styles/mixins.scss'),
]
}
},
configureWebpack: () => {
const config = {
name: title // 可以在 index.html 中被访问,用来注入页面标题
}
if (process.env.NODE_ENV === 'production') {
config.plugins = [
new WebpackBar({
name: title
})
],
// 生产环境清除 console.log
config.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: true,
compress: {
warnings: false,
drop_console: false,
drop_debugger: false,
pure_funcs: ['console.log'] // 清除 console.log
},
output: {
comments: false // 删除注释
}
}
})
]
}
}
return config
},
chainWebpack: config => {
// 当有很多页面时,它会导致太多毫无意义的请求
config.plugins.delete('prefetch')
// 开发环境 sourcemap 不包含列信息
config.when(process.env.NODE_ENV === 'development',
config => config.devtool('cheap-source-map')
)
// svg
const dir = path.resolve(__dirname, 'src/icons/svg')
config.module
.rule('svg-sprite')
.test(/\.svg$/)
.include
.add(dir)
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader').
options({ extract: false })
.end()
config.plugin('svg-sprite')
.use(require('svg-sprite-loader/plugin')), [{ pluginSprite: true }]
config.module.rule('svg').exclude.add(dir)
// 将运行代码单独生成文件
if (process.env.NODE_ENV !== 'development') {
config.optimization.runtimeChunk('single')
}
}
}