Skip to content
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

Merged
merged 1 commit into from
Nov 13, 2021
Merged

Allow specifying svgr options #11

merged 1 commit into from
Nov 13, 2021

Conversation

IanVS
Copy link
Contributor

@IanVS IanVS commented Jul 23, 2021

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 copying lib into the node_modules of my own typescript vite project, and the options were applied correctly and the typescript definitions worked as well.

@IanVS IanVS force-pushed the svgr-options branch 2 times, most recently from 2951cd0 to e5ac35e Compare July 23, 2021 18:21
@pd4d10
Copy link
Owner

pd4d10 commented Aug 11, 2021

Thanks! Can we use the built-in types after gregberge/svgr#555 merged?

@IanVS
Copy link
Contributor Author

IanVS commented Aug 11, 2021

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.

@LeonErath
Copy link

@pd4d10 Do you already know when you want to merge the PR? Would really help us have the options exposed.

@IanVS
Copy link
Contributor Author

IanVS commented Sep 28, 2021

After gregberge/svgr#601 is merged and released, I can update this PR to use the types from svgr directly.

@pd4d10
Copy link
Owner

pd4d10 commented Nov 8, 2021

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?

@pd4d10
Copy link
Owner

pd4d10 commented Nov 8, 2021

But it seems still in the alpha stage

@IanVS
Copy link
Contributor Author

IanVS commented Nov 8, 2021

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"
Copy link
Contributor Author

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')
Copy link
Contributor Author

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 }`
)
})
Copy link
Contributor Author

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/)
Copy link
Owner

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?

@pd4d10
Copy link
Owner

pd4d10 commented Nov 13, 2021

Great job!

The only thing I'm not sure about is the link in README. But not a big problem, I guess

@pd4d10 pd4d10 merged commit 20e5d6b into pd4d10:main Nov 13, 2021
@pd4d10
Copy link
Owner

pd4d10 commented Nov 13, 2021

v0.6.0 published. Still in 0.x, maybe it's better to ship 1.x after svgr v6 get stable

@IanVS IanVS deleted the svgr-options branch November 13, 2021 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass svgr config options
3 participants