Vue Cli 配置

引入 cdn

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
const isProduction = process.env.NODE_ENV === "production";

const cdn = {
// 开发环境
dev: {
css: [],
js: [],
},
// 生产环境
build: {
css: ["//lib.baomitu.com/swiper/7.4.1/swiper-bundle.css"],
js: [
"//lib.baomitu.com/vue/3.2.26/vue.cjs.js",
"//lib.baomitu.com/vuex/4.0.0/vuex.cjs.min.js",
"//lib.baomitu.com/vue-router/4.0.0/vue-router.cjs.min.js",
"//lib.baomitu.com/axios/0.18.0/axios.min.js",
"//lib.baomitu.com/jquery/3.6.0/jquery.min.js",
"//lib.baomitu.com/echarts/5.2.2/echarts.common.min.js",
"//lib.baomitu.com/swiper/7.4.1/swiper-bundle.esm.min.js",
],
},
};
chainWebpack: (config) => {
// 去掉console.log
config.optimization.minimizer("terser").tap((args) => {
args[0].terserOptions.compress.drop_console = true;
return args;
});
config.plugin("html").tap((args) => {
if (isProduction) {
args[0].cdn = cdn.build;
} else {
args[0].cdn = cdn.dev;
}
return args;
});
},

去掉 console.log

vue.config.js

1
2
3
4
5
6
7
8
chainWebpack: (config) => {
// 去掉console.log
config.optimization.minimizer("terser").tap((args) => {
args[0].terserOptions.compress.drop_console = true;
return args;
});
},