-
Notifications
You must be signed in to change notification settings - Fork 14
/
vue.config.js
94 lines (94 loc) · 3.69 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
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
const path = require('path');
const resolve = (dir) => path.join(__dirname, dir);
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); // 去除console
const CompressionWebpackPlugin = require('compression-webpack-plugin'); // gzip压缩
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
module.exports = {
publicPath: IS_PROD ? process.env.VUE_APP_PUBLIC_PATH : './', // 默认'/',部署应用包时的基本 URL
// outputDir: process.env.outputDir || 'dist', // 'dist', 生产环境构建文件的目录
// assetsDir: "", // 相对于outputDir的静态资源(js、css、img、fonts)目录
lintOnSave: false,
runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本
productionSourceMap: !IS_PROD, // 生产环境的 source map
parallel: require('os').cpus().length > 1,
filenameHashing: true,
pwa: {},
devServer: {
// overlay: { // 让浏览器 overlay 同时显示警告和错误
// warnings: true,
// errors: true
// },
// open: false, // 是否打开浏览器
// host: "localhost",
// port: "8080", // 代理断就
// https: false,
// hotOnly: false, // 热更新
proxy: {
'/api': {
target:
'https://www.easy-mock.com/mock/5bc75b55dc36971c160cad1b/sheets', // 目标代理接口地址
secure: false,
changeOrigin: true, // 开启代理,在本地创建一个虚拟服务端
// ws: true, // 是否启用websockets
pathRewrite: {
'^/api': '/',
},
},
},
},
configureWebpack: (config) => {
if (IS_PROD) {
const plugins = [];
plugins
.push(
new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {
drop_console: true,
drop_debugger: false,
minify: true,
pure_funcs: ['console.log'], // 移除console
},
},
sourceMap: true,
parallel: true,
}),
)
.push(
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.html$|\.css/,
threshold: 10240,
minRatio: 0.8,
}),
);
config.plugins = [...config.plugins, ...plugins];
}
},
chainWebpack: (config) => {
config.output
.filename(`[name]_[hash:4]_${process.env.VUE_APP_Version}.js`)
.end();
// 添加别名
config.resolve.alias
.set('@assets', resolve('src/assets'))
.set('@styles', resolve('src/assets/styles'))
.set('@components', resolve('src/components'))
.set('@views', resolve('src/views'))
.set('@router', resolve('src/router'))
.set('@static', resolve('src/static'));
// 打包分析
if (IS_PROD) {
config.plugin('webpack-report').use(BundleAnalyzerPlugin, [
{
analyzerMode: 'static',
},
]);
}
},
};