-
-
Notifications
You must be signed in to change notification settings - Fork 425
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
Add option to explicitly use named export #584
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/gregberge/svgr/Eerrm7dBYatRT3ja26EtxmrPVQXW |
Codecov Report
@@ Coverage Diff @@
## main #584 +/- ##
==========================================
- Coverage 91.38% 87.19% -4.19%
==========================================
Files 31 31
Lines 1079 570 -509
Branches 324 160 -164
==========================================
- Hits 986 497 -489
+ Misses 88 58 -30
- Partials 5 15 +10
Continue to review full report at Codecov.
|
I am using rollup and I was also looking for something like this. However, may I suggest a slightly different approach? Instead of adding Would perhaps result in a better UX (I for one find it odd that I can specify |
Any thoughts on this @gregberge? |
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 am thinking about using exportType
instead of forceNamedExport
. The option is more explicit.
@@ -227,7 +227,10 @@ export const getExport = ({ template }, opts) => { | |||
}) | |||
} | |||
|
|||
result += `export default ${exportName}` | |||
result += | |||
opts.forceNamedExport && opts.namedExport |
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.
The check of opts.namedExport
is not needed I think.
packages/rollup/README.md
Outdated
@@ -30,6 +30,8 @@ const App = () => ( | |||
) | |||
``` | |||
|
|||
By default, `@svgr/webpack` will try to export the React Component via default export if there is no default export handled by other loaders. If you prefer named export in any case, you may set the `forceNamedExport` option to `true`. |
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.
Not relative to rollup isn't it?
packages/webpack/README.md
Outdated
@@ -33,6 +33,8 @@ const App = () => ( | |||
) | |||
``` | |||
|
|||
By default, `@svgr/webpack` will try to export the React Component via default export if there is no default export handled by other loaders. If you prefer named export in any case, you may set the `forceNamedExport` option to `true`. |
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.
A paragraph to explain exportType
option please.
f42c705
to
61357ea
Compare
@fgblomqvist Thanks for your suggestion! Any of these options will drop the current default behavior which attempts to export it via default export if there's no any other loader/plugin using default export. Therefore, I'm afarid proceeding with this idea will introduce a huge breaking change. We could introduce an option of setting Because of this, I agree with the suggestion from @gregberge as a safer and more backward compatible option. |
@rayrw yeah sounds good to me, thanks for the lengthy explanation 🙂 |
Thanks! |
Would it be possible to get a release cut with this? |
@fgblomqvist you will have to wait a little bit longer. I will release a major and I have a stuff to do before releasing :) |
Summary
related: #557, kazijawad/esbuild-plugin-svgr#2
By default, when
@svgr/webpack
is the only loader handling svg files, it will always export the SVG React Component via default export. However, there may be cases where we prefer always exporting it via named export.In light of this, I'd like to propose adding a
forceNamedExport
exportType
(#584 (review)) config option to explicitly export the React Component via named export.Example
In Webpack config:
This will allow us in React side:
Test plan
added test cases and docs