-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying svgr options #11
Conversation
2951cd0
to
e5ac35e
Compare
Thanks! Can we use the built-in types after gregberge/svgr#555 merged? |
Yes, if/when that PR is merged, we should be able to re-use them. Unfortunately, who knows when/if that will happen. It has been open for a few months with no word from the maintainer. |
@pd4d10 Do you already know when you want to merge the PR? Would really help us have the options exposed. |
After gregberge/svgr#601 is merged and released, I can update this PR to use the types from svgr directly. |
Hi, @IanVS and @antialias , thanks for your contributions! I noticed that the svgr v6 already includes the type files. Can we update the PR to use its built-in types? |
But it seems still in the alpha stage |
Last time I tried the types weren't actually being published on npm. I think that has been fixed in alpha.1, so I will try again. I guess we need to look to check if v6 of svgr is a breaking change for this package, too. |
@@ -25,9 +25,9 @@ | |||
"vite": "^2.6.13" | |||
}, | |||
"peerDependencies": { | |||
"vite": "^2.0.0" | |||
"vite": "^2.6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bumped this because this is the version when transformWithEsbuild
was exposed: vitejs/vite#4882
return { | ||
name: 'vite:svgr', | ||
async transform(code, id) { | ||
if (id.endsWith('.svg')) { | ||
// TODO: exclude node_modules as an option | ||
const { default: convert } = await import('@svgr/core') | ||
const { transform: convert } = await import('@svgr/core') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting with svgr 6.0.0-alpha.3, there is no default export, instead there's a named transform
export.
'export default ReactComponent', | ||
`export { ReactComponent }` | ||
) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chained these together with a .then()
because it seemed cleaner, but I can revert this change if needed.
svgrPlugin({ | ||
svgrOptions: { | ||
icon: true, | ||
// ...svgr options (https://react-svgr.com/docs/options/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we put the v6 alpha options link here?
Great job! The only thing I'm not sure about is the link in README. But not a big problem, I guess |
v0.6.0 published. Still in 0.x, maybe it's better to ship 1.x after svgr v6 get stable |
Closes #10
This adds the ability to specify
svgrOptions
to the plugin, which are passed along to svgr.I also copied and slightly modified the type definitions from gregberge/svgr#555 and included them in the built files, so that consuming typescript projects have access to them.
I've tested this by running
npm run build
, then copyinglib
into thenode_modules
of my own typescript vite project, and the options were applied correctly and the typescript definitions worked as well.