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

Inline SVG Import plugin with Babel for react-native #306

Closed
inf3cti0n95 opened this issue May 10, 2019 · 8 comments
Closed

Inline SVG Import plugin with Babel for react-native #306

inf3cti0n95 opened this issue May 10, 2019 · 8 comments

Comments

@inf3cti0n95
Copy link

I have had a hard time, using SVG files in React native. And I want to change that. SVGR has a rich ecosystem. Which I think I can build upon a babel plugin to import svg files inline in react native project.

I need some support as general instruction and basic steps. As there is very little documentation on the core code of the SVGR packages.

I am building something like https://github.com/airbnb/babel-plugin-inline-react-svg .
Which is actually needed for react-native

@gregberge
Copy link
Owner

Hello @inf3cti0n95, I think you are looking for a SVGR Babel macro, you should give a look to https://github.com/evenchange4/svgr.macro

@inf3cti0n95
Copy link
Author

@neoziro I saw that! But, I want to import SVG files directly into tsx. And babel would transpile svg code to react-native-svg code

@gregberge
Copy link
Owner

Hmm I don't know how to do it, sorry :x

@kristerkari
Copy link

@inf3cti0n95 I'm not sure what your requirements are exactly, but you can try out my project that allows you to do import myimage from "./my-image.svg";. It uses React Native's Metro packager to do everything at bundle time. https://github.com/kristerkari/react-native-svg-transformer

@inf3cti0n95
Copy link
Author

inf3cti0n95 commented May 17, 2019

@kristerkari This is exactly what I was aiming for, but at babel transformation time. But, your package seems equally good. I'll try it. Thanks.

@inf3cti0n95
Copy link
Author

@kristerkari Your solution works just as I expected! Kudos! I dont' think we would need a babel plugin since the metro transformer works just fine for my use case.

@birdofpreyru
Copy link

Check this out: https://www.npmjs.com/package/@dr.pogodin/babel-preset-svgr - my solution for the problem:

  1. npm install --save-dev @dr.pogodin/babel-preset-svgr.
  2. Add @dr.pogodin/babel-preset-svgr to the list of presets in your Babel config.
  3. Instruct babel to process SVG files. In case you use Babel CLI to compile entire directories, do SVG compilation as a separate pass with --extensions '.svg' --keep-file-extension flags.
  4. Enjoy! :)

@gregberge
Copy link
Owner

Seems solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants