forked from unplugin/unplugin-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsx.ts
28 lines (27 loc) · 929 Bytes
/
jsx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { importModule } from 'local-pkg'
import { camelize } from '@iconify/utils/lib/misc/strings'
import type { Compiler } from './types'
export const JSXCompiler = (async (
svg,
collection,
icon,
options,
) => {
const svgrCore = await importModule('@svgr/core')
// check for v6/v7 transform (v7 on CJS it is in default), v5 default and previous versions
const svgr = svgrCore.transform // v6 or v7 ESM
|| (svgrCore.default ? (svgrCore.default.transform /* v7 CJS */ ?? svgrCore.default) : svgrCore.default)
|| svgrCore
let res = await svgr(
svg,
{
plugins: ['@svgr/plugin-jsx'],
},
{ componentName: camelize(`${collection}-${icon}`) },
)
// svgr does not provide an option to support preact (WHY?),
// we manually remove the react import for preact
if (options.jsx !== 'react')
res = res.replace('import * as React from "react";', '')
return res
}) as Compiler