forked from BNK-ALONG/teach-design-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
98 lines (95 loc) · 2.73 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
const path = require('path');
const resolve = (dir) => {
return path.join(__dirname, dir)
}
const CompressionPlugin = require('compression-webpack-plugin')
const ParalleeUglifyPlugin = require('webpack-parallel-uglify-plugin')
const isProduction = process.env.NODE_ENV === 'production'
const CDN = {
js: [
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js',
'https://cdn.bootcss.com/element-ui/2.13.0/index.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-router.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]'
],
css: [
'https://cdn.bootcss.com/element-ui/2.13.0/theme-chalk/index.css'
]
}
module.exports = {
publicPath: isProduction ? '/' : '/',
lintOnSave: false,
configureWebpack: config => {
if (isProduction) {
config.externals = {
'vue': 'Vue',
'vue-router': 'VueRouter',
'vuex': 'Vuex',
'element-ui': 'ELEMENT'
}
}
},
chainWebpack: (config) => {
config.resolve.alias
.set('@', resolve('src'))
.set('components', resolve('src/components'))
.set('views', resolve('src/views'))
if (isProduction) {
config
.plugin('html')
.tap(args => {
args[0].cdn = CDN;
return args;
})
config
.plugin('compressionPlugin')
.use(CompressionPlugin, [{
test: /\.js$|\.html$|\.css$/,
algorithm: 'gzip',
threshold: 10000, //对超过100000字节的文件进行压缩
minRatio: 0.8,
deleteOriginalAssets: false //是否删除原文件,不删除则原文件和.gz文件并存
}])
}
config
.plugin('ParalleeUglifyPlugin')
.use(ParalleeUglifyPlugin, [{
test: /\.js$/,
cacheDir: '.cache/',
//传递给UglifyJS的参数
uglifyJS: {
output: {
//最紧凑的输出
beautify: false,
// 删除所有注释
comments: false
},
compress: {
// 删除所有的`console`语句
drop_console: true,
//内嵌已定义但是只用到一次的变量
collapse_vars: true
},
// 在UglifyJS删除没有用到的代码时不输出警告
warnings: false,
}
}])
if (process.env.use_analyzer) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
.end()
}
},
devServer: {
hot: true,
compress: true,
proxy: {
'/': {
target: 'http://localhost:3000',
changeOrigin: true
}
}
},
productionSourceMap: false,
}