-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
146 lines (144 loc) · 3.79 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const TerserPlugin = require("terser-webpack-plugin"); // 去掉注释
const CompressionWebpackPlugin = require("compression-webpack-plugin"); // 开启压缩
const isProduction = process.env.NODE_ENV === "production";
module.exports = {
outputDir: "dist/explore",
publicPath: "/explore/",
productionSourceMap: false,
chainWebpack: config => {
// 开启打包日志
if (process.env.NODE_ENV !== "development") {
config
.plugin("webpack-bundle-analyzer")
.use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
// 压缩图片
config.module
.rule("images")
.test(/\.(gif|png|jpe?g|svg)$/i)
.use("image-webpack-loader")
.loader("image-webpack-loader")
.options({ bypassOnDebug: true })
.end();
}
},
configureWebpack: config => {
const plugins = [];
if (isProduction) {
// 处理生产环境的conlose
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ["console.log"] // 移除console
}
}
})
];
// 取消webpack警告的性能提示
config.performance = {
hints: "warning",
//入口起点的最大体积
maxEntrypointSize: 1000 * 500,
//生成文件的最大体积
maxAssetSize: 1000 * 1000,
//只给出 js 文件的性能提示
assetFilter: function(assetFilename) {
return assetFilename.endsWith(".js");
}
};
}
plugins.push(
new CompressionWebpackPlugin({
algorithm: "gzip",
test: /\.(js|css)$/, // 匹配文件名
threshold: 10000, // 对超过10k的数据压缩
deleteOriginalAssets: false, // 不删除源文件
minRatio: 0.8 // 压缩比
})
);
return { plugins };
},
pwa: {
iconPaths: {
favicon32: "img/icons/favicon-32x32.png",
favicon16: "img/icons/favicon-16x16.png",
appleTouchIcon: "img/icons/favicon-180x180.png",
maskIcon: "img/icons/favicon.svg",
msTileImage: "img/icons/favicon-144x144.png"
},
manifestOptions: {
icons: [
{
src: "img/icons/miaow-192x192.png",
sizes: "192x192",
type: "image/png"
},
{
src: "img/icons/miaow-512x512.png",
sizes: "512x512",
type: "image/png"
}
]
}
},
devServer: {
host: "0.0.0.0",
port: 8081,
// hot: true, // webpack模块 热更新
open: true, // 自动打开浏览器
compress: true, // 启用gzip压缩
https: true, // https协议
proxy: {
"/api": {
target: "http://localhost:7001",
ws: true,
changeOrigin: true,
pathRewrite: {
"^/api": ""
}
},
"/test": {
target: "http://localhost:7001",
ws: true,
changeOrigin: true,
pathRewrite: {
"^/test": ""
}
},
"/save": {
target: "http://hsbtr.cn:7001",
ws: true,
changeOrigin: true,
pathRewrite: {
"^/save": ""
}
},
"/socket.io": {
target: "http://localhost:7001",
ws: true,
changeOrigin: true
// pathRewrite: {
// "^/socket.io": "/socket.io/"
// }
},
"/socket-node": {
target: "http://localhost:7001",
ws: true,
changeOrigin: true
// pathRewrite: {
// "^/socket-node": "/socket-node/"
// }
},
"/sockjs-node": {
target: "http://localhost:7001",
ws: true,
changeOrigin: true
}
}
}
};