Skip to content

Commit

Permalink
fix: keep import statement at start
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Nov 9, 2021
1 parent 7d7af4a commit cb2fd7e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ export default function svgrPlugin(): Plugin {
const { default: convert } = await import('@svgr/core')

const svgCode = await fs.promises.readFile(id, 'utf8')
const componentCode = await convert(
let componentCode = await convert(
svgCode,
{},
{ componentName: 'ReactComponent' }
)
code =
code +
'\n' +
componentCode.replace(
'export default ReactComponent',
'export { ReactComponent }'
)
componentCode = componentCode.replace(
'export default ReactComponent',
'export { ReactComponent }'
)

const res = await transformWithEsbuild(code, id, { loader: 'jsx' })
const res = await transformWithEsbuild(
componentCode + '\n' + code,
id,
{ loader: 'jsx' }
)

return {
code: res.code,
Expand Down

0 comments on commit cb2fd7e

Please sign in to comment.