Skip to content

Commit

Permalink
支持显示svg, 添加svg-sprite-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
wanmaoor committed Jan 20, 2020
1 parent 853b480 commit 03f2382
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"lint-staged": "^9.5.0",
"sass": "^1.23.7",
"sass-loader": "^8.0.0",
"svg-sprite-loader": "^4.1.6",
"typescript": "~3.5.3",
"vue-template-compiler": "^2.6.10"
},
Expand Down
1 change: 1 addition & 0 deletions src/components/BottomLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
.view {
flex-grow: 1;
border: 1px solid #000;
overflow: auto;
}
</style>
7 changes: 6 additions & 1 deletion src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
declare module '*.vue' {
import Vue from 'vue'
import Vue from "vue"
export default Vue
}

declare module "*.svg" {
const content: string
export default content
}
6 changes: 5 additions & 1 deletion src/views/Money.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<template>
<BottomLayout>money</BottomLayout>
<BottomLayout>
<p>money</p>
</BottomLayout>
</template>

<script lang="ts">
import x from "@/assets/icons/edit.svg"
console.log(x)
export default {
name: "Money",
}
Expand Down
17 changes: 15 additions & 2 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
const path = require("path")

module.exports = {
lintOnSave: false
}
lintOnSave: false,
chainWebpack: config => {
const dir = path.resolve(__dirname, "src/assets/icons")

config.module
.rule("svg-sprite")
.test(/\.svg$/)
.include.add(dir).end() // 包含 icons 目录
.use("svg-sprite-loader").loader("svg-sprite-loader").options({extract: false}).end()
config.plugin("svg-sprite").use(require("svg-sprite-loader/plugin"), [{plainSprite: true}])
config.module.rule("svg").exclude.add(dir) // 其他 svg loader 排除 icons 目录
}
}
Loading

0 comments on commit 03f2382

Please sign in to comment.