-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathvue.config.js
59 lines (57 loc) · 1.47 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
/*
* @Author: 子君
* @Date: 2020-07-12 12:26:05
* @LastEditTime: 2020-07-27 09:44:24
* @LastEditors: 子君
* @Description: In User Settings Edit
* @FilePath: \vue-element-table\vue.config.js
*/
// const path = require('path')
// const resolve = dir => path.resolve(__dirname, '../', dir)
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
configureWebpack: config => {
if (isProd) {
// 配置webpack 压缩
config.plugins.push(
new CompressionWebpackPlugin({
test: /\.js$|\.html$|\.css$/,
// 超过4kb压缩
threshold: 4096
})
)
}
},
chainWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.externals({
'element-ui': 'element-ui',
'async-validator': 'async-validator',
lodash: 'lodash'
})
} else {
// 项目标题
config.plugin('html').tap(args => {
args[0].title = '前端有的玩'
return args
})
config
.entry('app')
.clear()
.add('./example/main.js')
}
},
// 不需要生产环境的 source map
productionSourceMap: false,
publicPath: !isProd ? '/' : '',
css: {
// 是否将css 提取到独立的文件,生产环境提取,开发环境不提取
extract: !!isProd,
// 开发模式开启css sourcemap
sourceMap: !isProd
},
devServer: {
port: 12315
}
}