Transforms imports to SVG files into React Components, and optimizes the SVGs with SVGO.
For example, the following code...
import React from 'react';
import CloseSVG from './close.svg';
const MyComponent = () => <CloseSvg />;
will be transformed into...
import React from 'react';
const CloseSVG = () => <svg>{/* ... */}</svg>;
const MyComponent = () => <CloseSvg />;
npm install --save-dev babel-plugin-inline-react-svg
.babelrc
{
"plugins": [
"inline-react-svg"
]
}
ignorePattern
- A pattern that imports will be tested against to selectively ignore imports.svgo
- svgo options. Example:
{
"plugins": [
[
"inline-react-svg",
{
"svgo": {
"plugins": [
{
"removeAttrs": { "attrs": "(data-name)" }
},
{
"cleanupIds": true
}
]
}
}
]
]
}
$ babel --plugins inline-react-svg script.js
require('babel-core').transform('code', {
plugins: ['inline-react-svg']
}) // => { code, map, ast };
Inspired by and code foundation provided by react-svg-loader.