-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
77 lines (72 loc) · 2.03 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
const TerserPlugin = require("terser-webpack-plugin");
const port = process.env.port || 80;
const outputDir = process.env.outputDir + "/" + process.env.outFileName + "-" + process.env.version;
const IS_PRODUCTION = process.env.NODE_ENV === "production";
const BASE_API = process.env.VUE_APP_BASE_API;
module.exports = {
// 设置打包目录
outputDir: outputDir,
// 设置静态资源的存储(相对于打包目录)
assetsDir: "static",
// 模式node_modules里的高级语法不编译,在这里设置允许编译
// transpileDependencies: ["vuetify"],
// 动态设置打包地址
publicPath: IS_PRODUCTION ? "./" : "/",
// 设置代理以可以跨域请求
devServer: {
host: "0.0.0.0",
// 设置本地代理端口
port: port,
// 设置是否自动打开浏览器
open: true,
proxy: {
[BASE_API]: {
// 服务器的地址
target: "http://api.test.com/",
// 如果是https请设置为true
// secure: true,
changeOrigin: true
// pathRewrite: {
// [`^${baseUrl}`]: ""
// }
}
}
},
chainWebpack: (config) => {
if (process.env.ANALYZE == "true") {
/**
* 分析器,可以查看打包之后的效果
* npm run build:analyzer
* 运行后会打开一个网址
*
*/
config.plugin("webpack-bundle-analyzer").use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
}
},
configureWebpack: () => {
let config = {};
if (IS_PRODUCTION) {
config.plugins = [
//打包环境去掉console.log
new TerserPlugin({
cache: true,
sourceMap: false,
// 多进程
parallel: true,
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
// 移除console
pure_funcs: ["console.log"]
}
}
})
];
return config;
}
}
};