From 84820b831a033f543f2b707b530712e6ba527b74 Mon Sep 17 00:00:00 2001 From: icssoa <2570063477@qq.com> Date: Thu, 11 Mar 2021 16:04:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20vue.config=20=E6=89=93?= =?UTF-8?q?=E5=8C=85=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 ++-- src/cool/index.js | 5 --- src/element.js | 32 +++++++++--------- vue.config.js | 84 +++++++++++++++++++++++++---------------------- 4 files changed, 63 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 0c987d9..a428fea 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "serve": "vue-cli-service serve", "build": "vue-cli-service build", "report": "vue-cli-service build --report", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint", + "inspect": "vue inspect --mode=production > output.js" }, "dependencies": { "axios": "^0.21.1", - "cl-admin": "^1.3.1", + "cl-admin": "^1.3.2", "cl-admin-crud": "^1.4.4", - "cl-admin-export": "^1.0.5", "cl-admin-theme": "^0.0.3", "clipboard": "^2.0.7", "codemirror": "^5.59.4", diff --git a/src/cool/index.js b/src/cool/index.js index c832433..b1adf95 100644 --- a/src/cool/index.js +++ b/src/cool/index.js @@ -1,5 +1,4 @@ import Crud from "cl-admin-crud"; -import Export from "cl-admin-export"; import Theme from "cl-admin-theme"; export default { @@ -30,10 +29,6 @@ export default { } } }, - { - name: "export", - value: Export - }, "copy", "distpicker", "demo", diff --git a/src/element.js b/src/element.js index ed190b9..8cc5187 100644 --- a/src/element.js +++ b/src/element.js @@ -50,28 +50,28 @@ import { Badge, Card, Rate, - Steps, - Step, + // Steps, + // Step, Carousel, CarouselItem, Collapse, CollapseItem, Cascader, - ColorPicker, - Transfer, - Container, - Header, - Aside, - Main, - Footer, - Timeline, - TimelineItem, + // ColorPicker, + // Transfer, + // Container, + // Header, + // Aside, + // Main, + // Footer, + // Timeline, + // TimelineItem, Link, Divider, Image, Calendar, - Backtop, - PageHeader, + // Backtop, + // PageHeader, CascaderPanel, Loading, MessageBox, @@ -134,8 +134,8 @@ Vue.use(Spinner); Vue.use(Badge); Vue.use(Card); Vue.use(Rate); -Vue.use(Steps); -Vue.use(Step); +// Vue.use(Steps); +// Vue.use(Step); Vue.use(Carousel); Vue.use(CarouselItem); Vue.use(Collapse); @@ -154,7 +154,7 @@ Vue.use(Link); Vue.use(Divider); Vue.use(Image); Vue.use(Calendar); -Vue.use(Backtop); +// Vue.use(Backtop); // Vue.use(PageHeader); Vue.use(CascaderPanel); Vue.use(Drawer); diff --git a/vue.config.js b/vue.config.js index a27f67b..ad11821 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,5 +1,4 @@ const HardSourceWebpackPlugin = require("hard-source-webpack-plugin"); - const isProduction = process.env.NODE_ENV === "production"; // 代理列表 @@ -50,7 +49,13 @@ module.exports = { }, chainWebpack: config => { - // svg + // 设置环境变量 + config.plugin('define').tap(args => { + args[0]['process.env'].PROXY_LIST = JSON.stringify(PROXY_LIST) + return args + }) + + // 设置 svg config.module.rule("svg").uses.clear(); config.module @@ -64,49 +69,47 @@ module.exports = { symbolId: "[name]" }); - // 去掉元素之间空格 - config.module - .rule("vue") - .use("vue-loader") - .loader("vue-loader") - .tap(options => { - options.compilerOptions.preserveWhitespace = true; - return options; - }) - .end(); - - // 移除 prefetch 插件 - config.plugins.delete("prefetch-index"); - - // 移除 preload 插件,避免加载多余的资源 - config.plugins.delete("preload-index"); - - // 设置环境变量 - config.plugin('define').tap(args => { - args[0]['process.env'].PROXY_LIST = JSON.stringify(PROXY_LIST) - return args - }) - // 生产模式下 if (isProduction) { - config.performance.set("hints", false); + // 去掉元素之间空格 + config.module + .rule("vue") + .use("vue-loader") + .loader("vue-loader") + .tap(options => { + options.compilerOptions.preserveWhitespace = true; + return options; + }) + .end(); + // 移除 prefetch 插件 + config.plugins.delete("prefetch-index"); + + // 移除 preload 插件,避免加载多余的资源 + config.plugins.delete("preload-index"); + + config.optimization.minimizer('terser').tap((args) => { + // 去掉注释 + args[0].terserOptions.output = { + comments: false + }; + return args + }) + + // 分割模块 config.optimization.splitChunks({ - chunks: "all", + chunks: 'all', + maxInitialRequests: Infinity, + minSize: 300000, + automaticNameDelimiter: '-', cacheGroups: { - // 公用模块抽离 - common: { - chunks: "initial", - minSize: 0, - minChunks: 2 - }, - // 第三方库抽离 vendor: { - priority: 1, - test: /node_modules/, - chunks: "initial", - minSize: 0, - minChunks: 2 + test: /[\\/]node_modules[\\/]/, + name(module) { + const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; + return `chunk.${packageName.replace('@', '')}`; + }, + priority: 10 } } }); @@ -114,6 +117,7 @@ module.exports = { }, configureWebpack: config => { - // config.plugins.push(new HardSourceWebpackPlugin()); + // 构建缓存 + config.plugins.push(new HardSourceWebpackPlugin()); } };