-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
88 lines (83 loc) · 2.39 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
const CompressionPlugin = require("compression-webpack-plugin");
const zlib = require("zlib");
module.exports = {
publicPath: "./",
outputDir: "dist",
assetsDir: "static",
indexPath: "index.html",
configureWebpack: {
performance: {
hints: "warning", // 枚举
maxAssetSize: 2000000, // 整数类型(以字节为单位)
maxEntrypointSize: 4000000, // 整数类型(以字节为单位)
assetFilter: function (assetFilename) {
// 提供资源文件名的断言函数
return assetFilename.endsWith(".css") || assetFilename.endsWith(".js");
},
},
},
chainWebpack(config) {
if (process.env.NODE_ENV === "production") {
// 对小图片进行处理减少请求次数
config.module
.rule("images")
.test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
.use("image-webpack-loader")
.loader("image-webpack-loader")
.options({bypassOnDebug: true})
.end();
// 对文件进行切片分块
config.optimization.splitChunks({
chunks: "all",
minSize: 2000000,
maxSize: 4000000,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: "~",
name: true,
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "com",
chunks: "all",
priority: -10,
},
default: {
minChunks: 2,
priority: -20,
name: "def",
reuseExistingChunk: true,
},
},
});
// 开启gizp
config.plugin("compression-webpack-plugin").use(
new CompressionPlugin({
filename: "[path][base].gz",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
})
);
config.plugin("compression-webpack-plugin").use(
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
})
);
config.optimization.runtimeChunk({
name: (entrypoint) => `runtimechunk~${entrypoint.name}`,
});
}
},
};