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

replace babel-svg-loader with svgr+new-url-loader #4595

Merged
merged 2 commits into from
Jul 18, 2021

Conversation

KutnerUri
Copy link
Contributor

@KutnerUri KutnerUri commented Jul 18, 2021

Proposed Changes

  • replace babel-plugin-named-asset-import with svgr and native webpack5 tools
  • remove svgr from main-ui (we don't have any inline svgs, but they are still allowed)

resolves #4462

workspace.jsonc Outdated Show resolved Hide resolved
@KutnerUri
Copy link
Contributor Author

@marella - you're going to get a lot of downloads 🤭

@GiladShoham GiladShoham merged commit cf63c7e into master Jul 18, 2021
@GiladShoham GiladShoham deleted the svg-as-react-loader branch July 18, 2021 18:09
{
loaderMap: {
svg: {
ReactComponent: '@svgr/webpack?-svgo,+titleProp,+ref![path]',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @KutnerUri. I'm not familiar with the code base but it looks like you were using some svgr options in your previous config. So you may want to include these options in the svgr loader config. Example:

{
  loader: '@svgr/webpack',
  options: {
    svgo: false,
    titleProp: true,
    ref: true,
  },
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, thanks for the catch. I will add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marella - I think it's safe to enable svgo (svg optimizer). We copied the config from Create React App.
What do you think?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why CRA has it disabled, might be related to facebook/create-react-app#5062
If you want to enable it, I think you should have a look at its default plugins. For example removeViewBox plugin is enabled by default but some users might not want viewBox to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. thanks :)

@KutnerUri KutnerUri mentioned this pull request Jul 19, 2021
GiladShoham pushed a commit that referenced this pull request Jul 19, 2021
- add the svgr props included in the previous setup, as per @marella's comment [here](#4595 (review)):
  - pass titleProp
  - pass ref
  - (do not disable `svgo` svg optimizer.)
- add the types needed to tag svg-as-react. (`ReactComponent`)
- add the same types to the `react-workspace-learn-bit` template. (not sure how to check it, but `bit new` isn't user facing yet)
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.

Only default export (as string) is available for SVG files runtime after bit start is executed
3 participants