-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
129 lines (124 loc) · 3.19 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
const path = require('path')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const CompressionPlugin = require('compression-webpack-plugin')
const MockData = require('./mockData/mock')
const env = process.env
const kbs = num => num * 1024
module.exports = {
publicPath: env.NODE_ENV === 'production' ? './' : '/',
productionSourceMap: env.VUE_APP_RUNTIME_ENV === 'production',
configureWebpack: () => ({
externals: {
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex',
axios: 'axios',
'element-ui': 'ELEMENT'
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'all',
test: /node_modules/,
name: 'vendor',
minChunks: 1,
maxInitialRequests: 5,
minSize: 0,
priority: 100
},
common: {
chunks: 'all',
test: /[\\/]src[\\/]js[\\/]/,
name: 'common',
minChunks: 2,
maxInitialRequests: 5,
minSize: 0,
priority: 60
},
styles: {
name: 'styles',
test: /\.(sa|sc|c)ss$/,
chunks: 'all',
enforce: true
},
runtimeChunk: {
name: 'manifest'
}
}
}
}
}),
chainWebpack: config => {
config.module
.rule('sass-resources')
.test(/\.(scss|sass)$/)
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
path.resolve(__dirname, 'src/assets/css/var.scss'),
path.resolve(__dirname, 'src/assets/css/mixins.scss')
]
})
.end()
if (env.VUE_APP_RUNTIME_ENV === 'development') {
config.plugin('define').tap(args => {
args[0]['process.env'].MOCK = true
return args
})
} else {
config.plugin('define').tap(args => {
args[0]['process.env'].MOCK = false
return args
})
}
if (env.NODE_ENV === 'production') {
config.plugin('webpack-bundle-analyzer').use(BundleAnalyzerPlugin)
}
if (env.VUE_APP_RUNTIME_ENV === 'production') {
const imageRule = config.module.rule('images')
imageRule.uses.clear()
imageRule
.use('url-loader')
.loader('url-loader')
.options({
limit: kbs(10),
fallback: {
loader: 'file-loader',
options: {
name: 'img/[name].[hash:8].[ext]'
}
}
})
/* 压缩图片 */
imageRule
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({ disable: false })
config.plugin('compression-webpack-plugin').use(CompressionPlugin, [
{
algorithm: 'gzip',
test: new RegExp(/\.(css|scss|sass|js|vue)$/i),
threshold: kbs(10)
}
])
}
},
devServer: {
host: '0.0.0.0',
disableHostCheck: true,
before(app) {
if (env.MOCK) {
MockData(app)
}
},
proxy: {
'/': {
target: 'http://106.12.208.84:8080/',
changeOrigin: true,
wx: true
}
}
}
}