From b4029677cfa3448bd0b0e33eb024a3fb8392141d Mon Sep 17 00:00:00 2001 From: Kane Date: Sat, 7 Jan 2023 15:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=BF=9B=E5=BA=A6=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin_system/src/components/svg/svg.js | 8 +-- .../web/admin_system/src/main.js | 4 +- .../web/admin_system/vue.config.js | 52 +++++++++++++++---- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/企业级管理系统/web/admin_system/src/components/svg/svg.js b/企业级管理系统/web/admin_system/src/components/svg/svg.js index 92d1657..fa452b4 100644 --- a/企业级管理系统/web/admin_system/src/components/svg/svg.js +++ b/企业级管理系统/web/admin_system/src/components/svg/svg.js @@ -2,21 +2,21 @@ * @Author: Kane * @Date: 2023-01-06 20:49:04 * @LastEditors: Kane - * @LastEditTime: 2023-01-06 20:58:42 + * @LastEditTime: 2023-01-07 12:17:28 * @FilePath: \admin_system\src\components\svg\svg.js * @Description: 导入svg图标 * * Copyright (c) ${2022} by Kane, All Rights Reserved. */ -const svgContext = require.context("./icons", true, /\.svg$/); -console.log(svgContext); +const context = require.context("./icons", false, /\.svg$/); +console.log(context); function requireAll(context) { return context.keys().map(context); } -const svgMap = requireAll(svgContext); +const svgMap = requireAll(context); console.log("导入svg"); console.log(svgMap); \ No newline at end of file diff --git a/企业级管理系统/web/admin_system/src/main.js b/企业级管理系统/web/admin_system/src/main.js index 863a2d2..536e6ef 100644 --- a/企业级管理系统/web/admin_system/src/main.js +++ b/企业级管理系统/web/admin_system/src/main.js @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2022-12-14 15:12:46 * @LastEditors: Kane - * @LastEditTime: 2023-01-07 11:23:18 + * @LastEditTime: 2023-01-07 15:03:29 * @FilePath: \admin_system\src\main.js * @Description: * @@ -12,7 +12,7 @@ import { createApp } from 'vue'; import App from './App.vue'; import router from './router'; import store from './store'; -import "@/components/svg/svg"; +//import "@/components/svg/svg"; import("./css/root.css"); import("./css/normalize.css"); diff --git a/企业级管理系统/web/admin_system/vue.config.js b/企业级管理系统/web/admin_system/vue.config.js index a30f8c0..ea1d581 100644 --- a/企业级管理系统/web/admin_system/vue.config.js +++ b/企业级管理系统/web/admin_system/vue.config.js @@ -2,20 +2,50 @@ * @Author: Kane * @Date: 2022-12-17 11:08:18 * @LastEditors: Kane - * @LastEditTime: 2023-01-07 11:12:20 + * @LastEditTime: 2023-01-07 12:08:14 * @FilePath: \admin_system\vue.config.js * @Description: * * Copyright (c) ${2022} by Kane, All Rights Reserved. */ -const { defineConfig } = require('@vue/cli-service'); -module.exports = defineConfig( +// const { defineConfig } = require('@vue/cli-service'); +// module.exports = defineConfig( +// { +// transpileDependencies: true, +// devServer: { +// open: true, +// host: "localhost", +// port: 8000, +// }, +// } +// ); +module.exports = { + transpileDependencies: true, + devServer: { + open: true, + host: "localhost", + port: 8000, + }, + chainWebpack: (config) => { - transpileDependencies: true, - devServer: { - open: true, - host: "localhost", - port: 8000, - }, - } -); + // svg 图标解析 + const svgRule = config.module.rule("svg"); //默认规则赋给 subRule 变量 + svgRule.uses.clear(); // 清除已有的所有规则。 + svgRule // 添加要替换的规则 + .use("svg-sprite-loader") + .loader("svg-sprite-loader") + .options({ + symbolId: "icon-[name]", + include: ["./src/components/svg/icons"] // 特别注意的目录路径 + }); + // 配置base64转换规则 + // config.module + // .rule('images') + // .use('url-loader') + // .loader('url-loader') + // .tap(options => Object.assign(options, { limit: 1 })); + + // 载入项目分析工具 + // config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin) + }, +}; \ No newline at end of file