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

exportType still doesn't work with rollupjs ?! #947

Open
Bonjour123 opened this issue Mar 11, 2024 · 1 comment
Open

exportType still doesn't work with rollupjs ?! #947

Bonjour123 opened this issue Mar 11, 2024 · 1 comment

Comments

@Bonjour123
Copy link

Bonjour123 commented Mar 11, 2024

🐛 Bug Report

exportType doesn't seems to be supported. 3 years ago I was using webpack it wasn't supported, 3 years later, I use vite (and so rollup.js) and exportType still isn't supported.

To Reproduce

Expected behavior

I expect to get a the component as default export, so that I'm not forced to use the long boilerplate "import {ReactComponent as My_svg} ...

@Bonjour123
Copy link
Author

Bonjour123 commented Mar 11, 2024

Understood.
The vite asset loader loads an asset by default exporting the url.
And svgr doesn't support enforcing the default export. see here.

This line should be if (opts.exportType!=="default" && (opts.state.caller?.previousExport || opts.exportType === 'named')) {
Or maybe it's by design, but right now I can't see any justification for this.

If it's by design and won't be fixed, then those who want the default export feature can:

  • git clone svgr
  • modify the line in ./packages/babel-plugin-transform-svg-component/src/variables.ts
  • cd ./packages/rollup
  • pnpm link --global
  • and wherever they want this feature: pnpm link --global @svgr/rollup

Then to replace all the named imports to default imports, you can use this regexp:

pattern: import \{ReactComponent as ([^}]*)}
replace: import $1

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

No branches or pull requests

1 participant