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

Difference with airbnb/babel-plugin-inline-react-svg #140

Closed
kopax opened this issue Jul 12, 2018 · 2 comments
Closed

Difference with airbnb/babel-plugin-inline-react-svg #140

kopax opened this issue Jul 12, 2018 · 2 comments

Comments

@kopax
Copy link

kopax commented Jul 12, 2018

One of my coworker did work with https://github.com/airbnb/babel-plugin-inline-react-svg in a distributed package.

I've told him to use svgr because it is now the default with create-react-app.

I would like to ask the same question as in #74 , how to deal when you are writing a distributed package?

What is the difference between this plugin and the babel plugin?

So far we didn't find a working way to import *.svg with webpack and rollup when it comes to distributed package.

@gregberge
Copy link
Owner

SVGR doesn't have a Babel plugin because it doesn't not work in sync mode (Prettier, etc...). But it is plan to support this way too.

@kopax
Copy link
Author

kopax commented Jul 22, 2018

I think now I can get an explanation:

It is better to use babel-plugin-inline-react-svg because it will export your svg as a react component during transpilation. This way, your svg react won't depend of any plugin anymore.

What's the difference with this plugin?

This plugin work with webpack, the svg is converted to react using loaders, and after the production build, you won't need any plugin as well. This fits if you are in an application, not in a module.

What about modules?

rollup can be used to create modules, and svgr have a module for it. If you want to bundle your code with rollup, it is perfect, but if you want to transpile your lib with babel, and have an aside configuration for producing a bundle with rollup, this plugin doesn't fit.

We personally choose to use @svgr/webpack for all svg that are imported in application, and we use babel-plugin-inline-react-svg for svg imported within modules.

We do not use @svgr/rollup only because it doesn't fit well with babel-plugin-inline-react-svg, but it would be nice if it could.

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

2 participants