-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
116 lines (115 loc) · 3.38 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
/*
* @Description:
* @Version:
* @Author: Linyer
* @Date: 2021-01-13 10:18:30
* @LastEditors: Linyer
* @LastEditTime: 2021-08-16 14:41:06
*/
const path = require('path');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports = {
publicPath: process.env.baseUrl || './',
outputDir: process.env.VUE_APP_OUTPUT_DIR || undefined,
assetsDir: 'static',
indexPath: 'index.html',
// 编译警告
lintOnSave: isProduction,
configureWebpack: (config) => {
//添加vscode 网页编辑器
config.plugins.push(new MonacoWebpackPlugin());
if (isProduction) {
// 开启gzip压缩
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
config.plugins.push(
new CompressionWebpackPlugin({
filename: '[file].gz[query]',
algorithm: 'gzip',
test: productionGzipExtensions,
threshold: 10240,
minRatio: 0.8,
})
);
} else {
// 开发环境配置
}
},
transpileDependencies: ['element-ui'],
chainWebpack: (config) => {
config.resolve.alias
.set('@', resolve('src'))
.set('assets', resolve('src/assets'))
.set('components', resolve('src/components'))
.set('apis', resolve('src/apis'))
.set('utils', resolve('src/utils'));
// 移除 prefetch 插件
config.plugins.delete('prefetch');
config.when(!isProduction, (config) => {
const now = new Date();
const version = [
[now.getFullYear(), now.getMonth() + 1, now.getDate()].join('-'),
[now.getHours(), now.getMinutes(), now.getSeconds()].join('H'),
]
.join('|')
.replace(/(?=\b\d\b)/g, ':');
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [
{
inline: /runtime\..*\.js$/,
},
])
.end();
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: `chunk-libs${version}`,
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial', // only package third parties that are initially dependent
},
elementUI: {
name: `chunk-elementUI${version}`, // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true,
},
},
});
config.optimization.runtimeChunk('single');
});
},
// 反向代理
devServer: {
port: 8080,
host: '0.0.0.0',
open: false,
https: false,
proxy: {
'/api': {
target: 'http://11',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/api': '',
},
},
},
},
css: {
requireModuleExtension: true,
},
};