-
Notifications
You must be signed in to change notification settings - Fork 22
/
vue.config.js
121 lines (112 loc) · 3.24 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
const path = require("path");
const resolve = (dir) => path.join(__dirname, dir);
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const isProd = ["production", "prod"].includes(process.env.NODE_ENV);
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
module.exports = {
publicPath: isProd ? "/" : "/",
chainWebpack: (config) => {
// 添加别名
config.resolve.alias
.set("@", resolve("src"))
.set("@assets", resolve("src/assets"))
.set("@image", resolve("src/assets/image"))
.set("@scss", resolve("src/assets/scss"))
.set("@components", resolve("src/components"));
config.optimization.splitChunks({
chunks: "all",
cacheGroups: {
vue: {
test: /[\\/]node_modules[\\/]vue[\\/]/,
name: "npm.vue",
},
vuex: {
test: /[\\/]node_modules[\\/]vuex[\\/]/,
name: "npm.vuex",
},
router: {
test: /[\\/]node_modules[\\/]vue[\\-]router[\\/]/,
name: "npm.router",
},
// vendor: {
// name: "npm.vendors",
// test: /[\\/]node_modules[\\/]/,
// chunks: "all",
// },
},
});
// 打包分析
if (isProd) {
config
.plugin("webpack-bundle-analyzer")
.use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin)
.end();
config.plugins.delete("prefetch");
// CDN
const cdn = {
// 访问https://unpkg.com/element-ui/lib/theme-chalk/index.css获取最新版本
css: [],
js: [
"//cdn.jsdelivr.net/npm/axios@0.26.0/dist/axios.min.js",
"//cdn.jsdelivr.net/npm/vue-i18n@8.27.0/dist/vue-i18n.min.js",
"//cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js",
],
};
config.plugin("html").tap((args) => {
// html 中添加 cdn
args[0].cdn = cdn;
return args;
});
}
},
configureWebpack: (config) => {
const plugins = [];
if (isProd) {
// config.module = {
// rules: [
// {
// test: /\.(scss|css)$/,
// resolve: { extensions: [".scss", ".css"] },
// use: [
// "style-loader",
// MiniCssExtractPlugin.loader,
// "css-loader",
// "postcss-loader?sourceMap",
// "resolve-url-loader?sourceMap",
// "sass-loader?sourceMap",
// ],
// },
// ],
// };
config.externals = {
axios: "axios",
VueI18n: "vue-i18n",
Editor: "@toast-ui/editor",
CodeMirror: "codemirror",
vue: "Vue",
};
plugins.push(
new CompressionWebpackPlugin({
filename: "[path][query][name].gz",
algorithm: "gzip",
test: productionGzipExtensions,
threshold: 10240,
minRatio: 0.8,
})
// new MiniCssExtractPlugin({
// filename: `styles/[name][hash:8].css`,
// })
);
}
config.plugins = [...config.plugins, ...plugins];
},
pluginOptions: {
i18n: {
locale: "Chinese",
fallbackLocale: "Chinese",
localeDir: "languages",
enableInSFC: true,
},
},
lintOnSave: false,
};