vite inline svg loader
作者:
思考蛙 | 来源:发表于
2021-07-14 15:18 被阅读0次import { getExtractedSVG } from "svg-inline-loader"
import type { Plugin } from "rollup"
import fs from "fs"
//TODO: remove this once https://github.com/vitejs/vite/pull/2909 gets merged
export const svgLoader: (options?: {
classPrefix?: string
idPrefix?: string
removeSVGTagAttrs?: boolean
warnTags?: boolean
removeTags?: boolean
warnTagAttrs?: boolean
removingTagAttrs?: boolean
}) => Plugin = (options?: {}) => {
return {
name: "vite-svg-patch-plugin",
transform: function (code, id) {
if (
id.endsWith(".svg")
) {
const extractedSvg = fs.readFileSync(id, "utf8")
return `export default '${getExtractedSVG(extractedSvg, options)}'`
}
return code
}
}
}
本文标题:vite inline svg loader
本文链接:https://www.haomeiwen.com/subject/ykpypltx.html
网友评论