This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
vue.config.js
222 lines (215 loc) · 5.29 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const WebpackCdnPlugin = require('webpack-cdn-plugin')
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
// 动态计算环境变量并以 `process.env.` 注入网站
// trick from: https://cli.vuejs.org/zh/guide/mode-and-env.html#在客户端侧代码中使用环境变量
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_COMMIT_HASH = process.env.COMMIT_REF
// console.log(process.env.NODE_ENV);
const { NODE_ENV } = process.env
// console.debug(process.env.VUE_APP_SIGNATURE_CONTRACT);
if (NODE_ENV === 'test') {
module.exports = {
chainWebpack: config => {
// 移除 prefetch 插件
config.plugins.delete('prefetch')
if (NODE_ENV === 'test') {
config.merge({
target: 'node',
devtool: 'inline-cheap-module-source-map',
externals: [
{
canvas: 'commonjs canvas'
},
'bufferutil',
'utf-8-validate'
]
})
// when target === 'node', vue-loader will attempt to generate
// SSR-optimized code. We need to turn that off here.
config.module
.rule('vue')
.use('vue-loader')
.tap(options => {
options.optimizeSSR = false
return options
})
}
}
}
return
}
module.exports = {
chainWebpack: config => {
// 移除 prefetch 插件
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()
if (NODE_ENV === 'test') {
config.merge({
target: 'node',
devtool: 'inline-cheap-module-source-map',
externals: [
{
canvas: 'commonjs canvas'
},
'bufferutil',
'utf-8-validate'
]
})
// when target === 'node', vue-loader will attempt to generate
// SSR-optimized code. We need to turn that off here.
config.module
.rule('vue')
.use('vue-loader')
.tap(options => {
options.optimizeSSR = false
return options
})
}
},
configureWebpack: {
externals: [
'axios',
{
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex',
'mavon-editor': 'MavonEditor'
// eosjs: 'Eos',
},
'moment',
'encoding',
'bufferutil',
'memcpy',
'utf-8-validate'
],
optimization: {
splitChunks: {
chunks: 'async',
minSize: 30000,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
},
plugins: [
// 为生产环境修改配置...
// new BundleAnalyzerPlugin(),
new WebpackCdnPlugin({
modules: [
{
name: 'axios',
var: 'axios',
path: 'dist/axios.min.js'
},
{
name: 'moment',
paths: ['min/moment.min.js', 'locale/zh-cn.js']
},
{
name: 'vue',
var: 'Vue',
path: 'dist/vue.runtime.min.js'
},
{
name: 'vue-router',
var: 'VueRouter',
path: 'dist/vue-router.min.js'
},
{
name: 'vuex',
var: 'Vuex',
path: 'dist/vuex.min.js'
},
{
name: 'mavon-editor',
var: 'mavonEditor',
cssOnly: true,
style: 'dist/css/index.css'
},
{
name: 'mavon-editor',
var: 'mavonEditor',
prodUrl:
'https://cdn.jsdelivr.net/gh/zhaokuohaha/mavonEditor@feature/lib-name/dist/mavon-editor.js'
}
/* {
name: 'eosjs',
var: 'Eos',
}, */
],
publicPath: '/node_modules',
crossOrigin: true
})
/*
new webpack.ContextReplacementPlugin( // 减少moment体积
/moment[/\\]locale$/,
/zh-cn/,
),
*/
]
},
css: {
loaderOptions: {
stylus: {
'resolve url': true,
import: []
}
}
},
pwa: {
msTileColor: '#1C9CFE',
themeColor: '#FFF',
workboxOptions: {
skipWaiting: true,
clientsClaim: true
},
iconPaths: {
favicon32: 'favicon.ico',
favicon16: 'favicon.ico',
appleTouchIcon: 'favicon.ico',
maskIcon: 'favicon.ico',
msTileImage: 'favicon.ico'
}
},
productionSourceMap: NODE_ENV === 'development' // 去掉map文件
// 代理
// devServer: {
// proxy: {
// "/": {
// target: "https://apitest.smartsignature.io"
// }
// }
// }
}