代码拉取完成,页面将自动刷新
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const path = require("path");
const isProduction = process.env.NODE_ENV === "production"; // 判断是否是生产环境
const cdn = {
css: [
"https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css"
],
js: [
"https://cdn.bootcdn.net/ajax/libs/vue/3.2.37/vue.global.prod.js",
"https://cdn.bootcdn.net/ajax/libs/vue-router/4.0.11/vue-router.global.js",
"https://cdn.bootcdn.net/ajax/libs/vuex/4.0.2/vuex.global.js",
"https://cdn.bootcdn.net/ajax/libs/axios/0.26.1/axios.min.js",
"https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.min.js"
]
};
module.exports = {
pluginOptions: {
"style-resources-loader": {
preProcessor: "less",
patterns: ["./src/style/common.less"]
}
},
chainWebpack: config => {
config.resolve.alias.set("@", path.join(__dirname, "src"));
config.optimization.minimizer("terser").tap(args => {
args[0].terserOptions.compress.drop_console = true;
return args;
});
config.plugin("webpack-bundle-analyzer").use(BundleAnalyzerPlugin);
if (isProduction) {
// 压缩代码
config.optimization.minimize(true);
// 分割代码
config.optimization.splitChunks({
chunks: "all"
});
// 生产环境注入cdn
config.plugin("html").tap(args => {
args[0].cdn = cdn;
return args;
});
// 生产环境下去除console
config.optimization.minimizer("terser").tap(arg => {
arg[0].terserOptions.compress.drop_console = true;
return arg;
});
}
},
configureWebpack: config => {
if (isProduction) {
// 用cdn方式引入
config.externals = {
vue: "Vue",
vuex: "Vuex",
"vue-router": "VueRouter",
axios: "axios",
bootstrap: "bootstrap"
};
}
// else {
// 为开发环境修改配置...}
// }
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。