forked from unplugin/unplugin-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue3.ts
21 lines (16 loc) · 743 Bytes
/
vue3.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { importModule } from 'local-pkg'
import { handleSVGId } from '../svgId'
import type { Compiler } from './types'
export const Vue3Compiler = (async (svg: string, collection: string, icon: string) => {
const { compileTemplate } = await importModule('@vue/compiler-sfc')
const { injectScripts, svg: handled } = handleSVGId(svg)
let { code } = compileTemplate({
source: handled,
id: `${collection}:${icon}`,
filename: `${collection}-${icon}.vue`,
})
code = code.replace(/^export /gm, '')
code += `\n\nexport default { name: '${collection}-${icon}', render${injectScripts ? `, data() {${injectScripts};return { idMap }}` : ''} }`
code += '\n/* vite-plugin-components disabled */'
return code
}) as Compiler