-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
91 lines (89 loc) · 2.68 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
const path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const isProd = process.env.NODE_ENV === "production";
module.exports = {
runtimeCompiler: true,
lintOnSave: false,
css: {
loaderOptions: {
// sass: {
// prependData: '@import "@/assets/css/variables.scss";',
// }
},
},
devServer: {
host: "127.0.0.1",
port: 8081, // 端口
// proxy: {
// "/api": {
// target: "http://192.168.51.210:3300",
// ws: false,
// changeOrigin: true,
// },
// },
},
productionSourceMap: false,
configureWebpack: (config) => {
// 别名
config.resolve = {
alias: {
"@": path.resolve(__dirname, "./src"),
},
extensions: [".js", ".vue", ".json"],
};
if (true) {
// 开启分离js
config.optimization = {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
maxAsyncRequests: 30,
maxInitialRequests: 30,
minSize: 20000,
maxSize: 1000000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace("@", "")}`;
},
},
},
},
// css压缩
// minimizer: [
// // For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
// // `...`,
// new CssMinimizerPlugin()
// ],
// minimize: true
};
// uglifyjs
config.plugins.push(
new UglifyJsPlugin({
uglifyOptions: {
compress: {
drop_debugger: true,
drop_console: true, // 生产环境自动删除console
dead_code: true, // 移除没被引用的代码
loops: true, // 当do、while 、 for循环的判断条件可以确定是,对其进行优化
},
warnings: false,
},
sourceMap: false,
parallel: true, // 使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
})
);
// 打包分析工具
// config.plugins.push(new BundleAnalyzerPlugin());
} else {
config.devtool = "source-map";
}
},
};