1 Star 1 Fork 0

Jane/zheye

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vue.config.js 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
Jane 提交于 2022-08-05 18:26 . feat:更新README
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 {
// 为开发环境修改配置...}
// }
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/yang-yu1997/zheye.git
git@gitee.com:yang-yu1997/zheye.git
yang-yu1997
zheye
zheye
master

搜索帮助