-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jordan Gensler
committed
Sep 19, 2016
1 parent
3bb94bc
commit c8f9e46
Showing
1 changed file
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,60 @@ | ||
# babel-plugin-inline-react-svg | ||
|
||
Inlines requires to SVG files so that they can be used seamlessly in your components. | ||
Transforms imports to SVG files into React Components, and optimizes the SVGs with [SVGO](https://github.com/svg/svgo/). | ||
|
||
For example, the following code... | ||
|
||
```jsx | ||
import React from 'react'; | ||
import CloseSVG from './close.svg'; | ||
|
||
export default const MyComponent = () => <CloseSvg />; | ||
``` | ||
|
||
will be transformed into... | ||
|
||
```jsx | ||
import React from 'react'; | ||
const CloseSVG = () => <svg>{* ... *}</svg>; | ||
|
||
export default const MyComponent = () => <CloseSvg />; | ||
``` | ||
|
||
## Installation | ||
|
||
``` | ||
npm install --save-dev babel-plugin-inline-react-svg | ||
``` | ||
|
||
## Usage | ||
|
||
### Via `.babelrc` (Recommended) | ||
|
||
**.babelrc** | ||
|
||
```json | ||
{ | ||
"plugins": [ | ||
"inline-react-svg" | ||
] | ||
} | ||
``` | ||
|
||
### Via CLI | ||
|
||
```sh | ||
$ babel --plugins inline-react-svg script.js | ||
``` | ||
|
||
### Via Node API | ||
|
||
|
||
```javascript | ||
require('babel-core').transform('code', { | ||
plugins: ['inline-react-svg'] | ||
}) // => { code, map, ast }; | ||
``` | ||
|
||
--- | ||
|
||
Inspired by and code foundation provided by [react-svg-loader](https://github.com/boopathi/react-svg-loader). |