-
Notifications
You must be signed in to change notification settings - Fork 3
Only use svgr in specific contexts #988
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
Conversation
|
// @see https://webpack.js.org/guides/dependency-management/#context-module-api | ||
const iconDir = require.context('../../assets/icons', false, /\.svg$/); | ||
const iconDir = require.context( | ||
'!!@svgr/webpack!../../assets/icons', |
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.
Could you add a comment explaining this svgr syntax, or linking to some docs?
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.
Sure, this is more webpack syntax than svgr but I've linked to docs for both now.
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.
Sounds like a great idea to me, and I'm very much in favor of reducing the complexity of our app. I'll leave final approval to @calebeby since this touches webpack, but it LGTM.
FYI, no need for anyone to review till I've marked as "ready for review" and assigned a reviewer. Was waiting till the deploy preview finished so I could make the testing instructions easier. |
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.
🎉 Thanks for catching that!
Overview
I started making an unrelated change to a pattern, but on every save I saw errors about SVG loading in the Terminal. These appear to be uncaught issues with changes from #862, which caused the icon listing to fail (which explains its disappearance from our deploy).
I tried a few different solutions, but there were three points of Webpack configuration around
.svg
files and whenever I fixed one a different one would have issues.I looked back at the history of why there was so much SVG configuration, and realized it was all due to #503, specifically the need to convert SVG files to React components for the sole purpose of documentation.
Since that's the only context where we'd want to do that, I decided to use inline loaders within that file instead. While that's not a great practice for an entire project, it keeps this complexity confined to the single file that needs it.
Screenshots
Testing
On the deploy preview...
/CC @spaceninja @calebeby