-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
91 lines (88 loc) · 2.22 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')
function resolve(dir) {
return path.join(__dirname, './', dir)
}
// cdn 预加载使用
const externals = {
"core-js": "CorrJs",
"postcss-write-svg": "PostcssWriteSvg",
"svg-sprite-loader": "SvgSpriteLoader",
"vue": "Vue",
"vue-router": "VueRouter",
"vuex": "Vuex"
}
const cdn = {
// 开发环境
dev: {
css: [],
js: [
'https://cdn.bootcss.com/core-js/2.6.9/core.js'
]
},
// 生产环境
build: {
css: [],
js: [
'https://cdn.bootcss.com/core-js/2.6.9/core.js'
]
}
}
module.exports = {
configureWebpack: config => {
const myConfig = {}
if (process.env.NODE_ENV === 'production') {
// 生产环境
myConfig.externals = externals
}
if(process.env.NODE_ENV === 'development'){
// 开发环境
myConfig.devServer = {
disableHostCheck: true
}
}
return myConfig
},
chainWebpack: config => {
/**
* 添加CDN参数到htmlWebpackPlugin配置中, 详见public/index.html 修改
*/
config.plugin('html').tap(args => {
if (process.env.NODE_ENV === 'production') {
args[0].cdn = cdn.build
}
if (process.env.NODE_ENV === 'development') {
args[0].cdn = cdn.dev
}
return args
})
// svg loader
const svgRule = config.module.rule('svg') // 找到svg-loader
svgRule.uses.clear() // 清除已有的loader, 如果不这样做会添加在此loader之后
svgRule.exclude.add(/node_modules/) // 正则匹配排除node_modules目录
svgRule // 添加svg新的loader处理
.test(/\.svg$/)
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
// 修改images loader 添加svg处理
const imagesRule = config.module.rule('images')
imagesRule.exclude.add(resolve('src/icons'))
config.module
.rule('images')
.test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
},
devServer: {
open: true,
hot: true,
// https: true,
proxy: {
'/api': {
target: 'http://localhost:4000/api',
ws: false,
changeOrigin: true
}
}
}
}