1 | # @svgr/rollup
|
2 |
|
3 | [](https://travis-ci.org/smooth-code/svgr)
|
4 | [](https://www.npmjs.com/package/@svgr/rollup)
|
5 | [](https://github.com/smooth-code/svgr/blob/master/LICENSE)
|
6 |
|
7 | Rollup plugin for SVGR.
|
8 |
|
9 | ```
|
10 | npm install @svgr/rollup --save-dev
|
11 | ```
|
12 |
|
13 | In your `rollup.config.js`:
|
14 |
|
15 | ```js
|
16 | {
|
17 | plugins: [svgr()]
|
18 | }
|
19 | ```
|
20 |
|
21 | In your code:
|
22 |
|
23 | ```js
|
24 | import Star from './star.svg'
|
25 |
|
26 | const 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 |
|
43 | It is possible to use it with [`url`](https://github.com/rollup/rollup-plugin-url).
|
44 |
|
45 | In your `rollup.config.js`:
|
46 |
|
47 | ```js
|
48 | {
|
49 | plugins: [url(), svgr()]
|
50 | }
|
51 | ```
|
52 |
|
53 | In your code:
|
54 |
|
55 | ```js
|
56 | import starUrl, { ReactComponent as Star } from './star.svg'
|
57 |
|
58 | const App = () => (
|
59 | <div>
|
60 | <img src={starUrl} alt="star" />
|
61 | <Star />
|
62 | </div>
|
63 | )
|
64 | ```
|
65 |
|
66 | The named export defaults to `ReactComponent`, but can be customized with the `namedExport` option.
|
67 |
|
68 | Please 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 |
|
70 | If you prefer named export in any case, you may set the `exportType` option to `named`.
|
71 |
|
72 | ### Use your own Babel configuration
|
73 |
|
74 | By default, `@svgr/rollup` applies a babel transformation with [optimized configuration](https://github.com/gregberge/svgr/blob/main/packages/rollup/src/index.ts). 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 |
|
84 | MIT
|