UNPKG

1.98 kBMarkdownView Raw
1# @svgr/rollup
2
3[![Build Status](https://img.shields.io/travis/smooth-code/svgr.svg)](https://travis-ci.org/smooth-code/svgr)
4[![Version](https://img.shields.io/npm/v/@svgr/rollup.svg)](https://www.npmjs.com/package/@svgr/rollup)
5[![MIT License](https://img.shields.io/npm/l/@svgr/rollup.svg)](https://github.com/smooth-code/svgr/blob/master/LICENSE)
6
7Rollup plugin for SVGR.
8
9```
10npm install @svgr/rollup --save-dev
11```
12
13In your `rollup.config.js`:
14
15```js
16{
17 plugins: [svgr()]
18}
19```
20
21In your code:
22
23```js
24import Star from './star.svg'
25
26const App = () => (
27 <div>
28 <Star />
29 </div>
30)
31```
32
33### Passing options
34
35```js
36{
37 plugins: [svgr({ native: true })]
38}
39```
40
41### Using with `url` plugin
42
43It is possible to use it with [`url`](https://github.com/rollup/rollup-plugin-url).
44
45In your `rollup.config.js`:
46
47```js
48{
49 plugins: [url(), svgr()]
50}
51```
52
53In your code:
54
55```js
56import starUrl, { ReactComponent as Star } from './star.svg'
57
58const App = () => (
59 <div>
60 <img src={starUrl} alt="star" />
61 <Star />
62 </div>
63)
64```
65
66The named export defaults to `ReactComponent`, but can be customized with the `namedExport` option.
67
68Please note that by default, `@svgr/rollup` will try to export the React Component via default export if there is no other plugin handling svg files with default export. When there is already any other plugin using default export for svg files, `@svgr/rollup` will always export the React component via named export.
69
70If you prefer named export in any case, you may set the `exportType` option to `named`.
71
72### Use your own Babel configuration
73
74By default, `@svgr/rollup` applies a babel transformation with [optimized configuration](https://github.com/smooth-code/svgr/blob/master/packages/rollup/src/index.js). In some case you may want to apply a custom one (if you are using Preact for an example). You can turn off Babel transformation by specifying `babel: false` in options.
75
76```js
77{
78 plugins: [svgr({ babel: false })]
79}
80```
81
82## License
83
84MIT