forked from snowzijun/vue-vant-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
80 lines (76 loc) · 1.96 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
/*
* @Author: 子君
* @Date: 2020-07-12 12:26:05
* @LastEditTime: 2020-07-17 12:59:55
* @LastEditors: 子君
* @Description: In User Settings Edit
* @FilePath: \vue-base\vue.config.js
*/
const webpackConfig = require('./config/webpack.config.js')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
// 开发模式代理地址 TODO: 按需修改
const DEV_URL = 'http://127.0.0.1'
// mock模式代理地址,为了方便演示,这里使用了fastmock线上服务,建议使用yapi,可以搭建私服, TODO: 按需修改
const MOCK_URL =
'https://www.fastmock.site/mock/52683c53c56c5c59bc1e46d24a3550b6/zijun'
module.exports = {
configureWebpack: config => {
if (isProd) {
// 配置webpack 压缩
config.plugins.push(
new CompressionWebpackPlugin({
test: /\.js$|\.html$|\.css$/,
// 超过4kb压缩
threshold: 4096
})
)
}
},
chainWebpack: config => {
// 项目标题
config.plugin('html').tap(args => {
args[0].title = '前端有的玩'
return args
})
webpackConfig(config)
},
// 不需要生产环境的 source map
productionSourceMap: false,
publicPath: !isProd ? '/' : '',
css: {
// 是否将css 提取到独立的文件,生产环境提取,开发环境不提取
extract: !!isProd,
// 开发模式开启css sourcemap
sourceMap: !isProd,
loaderOptions: {
less: {
lessOptions: {
modifyVars: {
hack: 'true;@import "~@/style/_variables.less"'
}
}
}
}
},
devServer: {
port: 12315,
proxy: {
'^/api': {
target: DEV_URL,
changeOrigin: false,
pathRewrite: {
'^/api': ''
}
},
'^/mock/': {
// TODO: 添加 mock地址
target: MOCK_URL,
changeOrigin: false,
pathRewrite: {
'^/mock': ''
}
}
}
}
}