Commit 2bf3209a by Jaxon

feat: 添加项目对 svg 的处理

1 parent b2628ee9
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
"sass": "^1.99.0", "sass": "^1.99.0",
"sass-loader": "^8.0.2", "sass-loader": "^8.0.2",
"script-ext-html-webpack-plugin": "^2.1.4", "script-ext-html-webpack-plugin": "^2.1.4",
"svg-sprite-loader": "6.0.11",
"vue-loader": "^15.9.8", "vue-loader": "^15.9.8",
"vue-template-compiler": "^2.6.11", "vue-template-compiler": "^2.6.11",
"webpack-bundle-analyzer": "^3.8.0" "webpack-bundle-analyzer": "^3.8.0"
......
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask id="mask0_2025_1825" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="16" height="16">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 0H16V16H0V0Z" fill="white"/>
</mask>
<g mask="url(#mask0_2025_1825)">
<path d="M3.36821 2.31006H6.12593C6.8314 2.31006 7.18414 2.66279 7.18414 3.36826V5.31432C7.18414 6.01978 6.8314 6.37252 6.12593 6.37252H3.36821C2.66274 6.37252 2.31 6.01978 2.31 5.31432V3.36826C2.31 2.66279 2.66274 2.31006 3.36821 2.31006Z" fill="white"/>
<path d="M9.86778 9.62134H12.6255C13.331 9.62134 13.6837 9.97408 13.6837 10.6795V12.6256C13.6837 13.3311 13.331 13.6838 12.6255 13.6838H9.86778C9.16231 13.6838 8.80957 13.3311 8.80957 12.6256V10.6795C8.80957 9.97408 9.16231 9.62134 9.86778 9.62134Z" fill="white"/>
<path d="M3.36821 7.18408H6.12593C6.8314 7.18408 7.18414 7.53682 7.18414 8.24229V12.6254C7.18414 13.3309 6.8314 13.6836 6.12593 13.6836H3.36821C2.66274 13.6836 2.31 13.3309 2.31 12.6254V8.24229C2.31 7.53682 2.66274 7.18408 3.36821 7.18408Z" fill="white"/>
<path d="M9.86778 2.31006H12.6255C13.331 2.31006 13.6837 2.66279 13.6837 3.36826V7.34503C13.6837 8.05049 13.331 8.40323 12.6255 8.40323H9.86778C9.16231 8.40323 8.80957 8.05049 8.80957 7.34503V3.36826C8.80957 2.66279 9.16231 2.31006 9.86778 2.31006Z" fill="white"/>
</g>
</svg>
const requireAll = requireContext => requireContext.keys().map(requireContext);
const req = require.context("./", false, /\.svg$/);
requireAll(req);
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
<path d="M160 832h704v64H96V128h64v704z" fill="currentColor" />
<path d="M320 672a48 48 0 1 1 0-96 48 48 0 0 1 0 96zm192-128a48 48 0 1 1 0-96 48 48 0 0 1 0 96zm192-192a48 48 0 1 1 0-96 48 48 0 0 1 0 96zm192-128a48 48 0 1 1 0-96 48 48 0 0 1 0 96z" fill="currentColor" />
<path d="m298.88 594.24-45.76-44.8 194.56-198.4a32 32 0 0 1 44.8-1.28l161.92 144.96 217.6-229.12 46.08 43.84-238.72 251.2a32 32 0 0 1-44.8 1.6L470.4 415.04 298.88 594.24z" fill="currentColor" />
</svg>
<template>
<svg
class="svg-icon"
:style="iconStyle"
aria-hidden="true"
>
<use :xlink:href="iconName" />
</svg>
</template>
<script>
export default {
name: "SvgIcon",
props: {
name: {
type: String,
required: true,
},
size: {
type: [String, Number],
default: "1em",
},
color: {
type: String,
default: "currentColor",
},
},
computed: {
iconName() {
return `#icon-${this.name}`;
},
iconStyle() {
const size = typeof this.size === "number" ? `${this.size}px` : this.size;
return {
width: size,
height: size,
fill: this.color,
};
},
},
};
</script>
<style lang="scss" scoped>
.svg-icon {
display: inline-block;
vertical-align: middle;
overflow: hidden;
}
</style>
...@@ -12,6 +12,7 @@ import router from "./router"; ...@@ -12,6 +12,7 @@ import router from "./router";
import store from "./store"; import store from "./store";
import { bus, store as local, tools, util } from "./utils"; import { bus, store as local, tools, util } from "./utils";
import "@/assets/css/index.scss"; import "@/assets/css/index.scss";
import "@/assets/icons";
import "./utils/util"; import "./utils/util";
import "@/components"; import "@/components";
// import mixin from './mixins/index' // import mixin from './mixins/index'
......
...@@ -4,6 +4,7 @@ const defaultSettings = require("./src/config/conf.js"); ...@@ -4,6 +4,7 @@ const defaultSettings = require("./src/config/conf.js");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin; const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const resolve = dir => path.join(__dirname, dir); const resolve = dir => path.join(__dirname, dir);
const iconsPath = resolve("src/assets/icons");
// page title // page title
const name = defaultSettings.title || "登录中..."; const name = defaultSettings.title || "登录中...";
// 生产环境,测试和正式 // 生产环境,测试和正式
...@@ -133,6 +134,25 @@ module.exports = { ...@@ -133,6 +134,25 @@ module.exports = {
// 别名 alias // 别名 alias
config.resolve.alias config.resolve.alias
.set("@", resolve("src")); .set("@", resolve("src"));
config.module
.rule("svg")
.exclude
.add(iconsPath)
.end();
config.module
.rule("icons")
.test(/\.svg$/)
.include
.add(iconsPath)
.end()
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({
symbolId: "icon-[name]",
})
.end();
// .set('assets', resolve('src/assets')) // .set('assets', resolve('src/assets'))
// .set('api', resolve('src/api')) // .set('api', resolve('src/api'))
// .set('views', resolve('src/views')) // .set('views', resolve('src/views'))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!