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

Add an SVG inline #56

Open
microcipcip opened this issue Apr 5, 2019 · 7 comments
Open

Add an SVG inline #56

microcipcip opened this issue Apr 5, 2019 · 7 comments

Comments

@microcipcip
Copy link

Is there a way to add an SVG inline? For example the following code breaks the SSR:

import { ReactComponent as Logo } from './logo.svg';

I can create a repo with the issue if needed.

@francisrod01
Copy link

This problably is a bug.

Note: this feature is available with [email protected] and higher
https://facebook.github.io/create-react-app/docs/adding-images-fonts-and-files

To use SVG inline, please read this by StackOverflow:
https://stackoverflow.com/questions/42289227/unable-to-import-svg-file-into-react

@microcipcip
Copy link
Author

@francisrod01 thanks for the reply, I am using [email protected], regarding that solution, I think I'd have to eject CRA, isn't it? Is there any other solution that doesn't require changing webpack config?

@pkev777
Copy link

pkev777 commented May 13, 2019

Faced with the same issue. As far as I think we should use correct babel plugin in @babel/register to transform svg imports. But I can't understand which plugin we should use? As I see create-react-app uses @svgr/webpack but it's compatible only with webpack

@microcipcip
Copy link
Author

microcipcip commented May 13, 2019

@pkev777 I have investigated this issue and it seems that the only package that doesn't break SSR is https://github.com/airbnb/babel-plugin-inline-react-svg , the reason is that this package converts SVGs files into JS objects.

I haven't fixed it yet though, I don't know how to integrate it with the server.

@pkev777
Copy link

pkev777 commented May 13, 2019

@microcipcip but this requires eject(. Or do your find some way how to use it without ejection?

@microcipcip
Copy link
Author

@pkev777 That's why I haven't tried it yet, I don't want to eject, so for now I've converted my SVGs in React components ;)

@cereallarceny cereallarceny mentioned this issue Jun 19, 2019
16 tasks
@cereallarceny
Copy link
Owner

Hey, my apologies for the long wait @microcipcip - I'm looking to ensure this is fixed with version 2.0. If you're interested, I could really use your thoughts for what you'd like to see in the upcoming version. Feel free to comment on the issue here with any suggestions. :)

@francisrod01 @pkev777

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

4 participants