source: frontend/node_modules/@svgr/webpack/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[9af201e]1# @svgr/webpack
2
3[![Build Status](https://img.shields.io/travis/gregberge/svgr.svg)](https://travis-ci.org/gregberge/svgr)
4[![Version](https://img.shields.io/npm/v/@svgr/webpack.svg)](https://www.npmjs.com/package/@svgr/webpack)
5[![MIT License](https://img.shields.io/npm/l/@svgr/webpack.svg)](https://github.com/gregberge/svgr/blob/master/LICENSE)
6
7Webpack loader for SVGR.
8
9```
10npm install @svgr/webpack --save-dev
11```
12
13## Usage
14
15In your `webpack.config.js`:
16
17```js
18{
19 test: /\.svg$/,
20 use: ['@svgr/webpack'],
21}
22```
23
24In your code:
25
26```js
27import Star from './star.svg'
28
29const App = () => (
30 <div>
31 <Star />
32 </div>
33)
34```
35
36### Passing options
37
38```js
39{
40 test: /\.svg$/,
41 use: [
42 {
43 loader: '@svgr/webpack',
44 options: {
45 native: true,
46 },
47 },
48 ],
49}
50```
51
52### Using with `url-loader` or `file-loader`
53
54It is possible to use it with [`url-loader`](https://github.com/webpack-contrib/url-loader) or [`file-loader`](https://github.com/webpack-contrib/file-loader).
55
56In your `webpack.config.js`:
57
58```js
59{
60 test: /\.svg$/,
61 use: ['@svgr/webpack', 'url-loader'],
62}
63```
64
65In your code:
66
67```js
68import starUrl, { ReactComponent as Star } from './star.svg'
69
70const App = () => (
71 <div>
72 <img src={starUrl} alt="star" />
73 <Star />
74 </div>
75)
76```
77
78The named export defaults to `ReactComponent`, but can be customized with the `namedExport` option.
79
80### Use your own Babel configuration
81
82By default, `@svgr/webpack` includes a `babel-loader` with [an optimized configuration](https://github.com/gregberge/svgr/blob/master/packages/webpack/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.
83
84```js
85// Example using preact
86{
87 test: /\.svg$/,
88 use: [
89 {
90 loader: 'babel-loader',
91 options: {
92 presets: ['preact', 'env'],
93 },
94 },
95 {
96 loader: '@svgr/webpack',
97 options: { babel: false },
98 }
99 ],
100}
101```
102
103### Handle SVG in CSS, Sass or Less
104
105It is possible to detect the module that requires your SVG using [`Rule.issuer`](https://webpack.js.org/configuration/module/#rule-issuer) in Webpack. Using it you can specify two different configurations for JavaScript and the rest of your files.
106
107```js
108[
109 {
110 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
111 issuer: {
112 test: /\.jsx?$/
113 },
114 use: ['babel-loader', '@svgr/webpack', 'url-loader']
115 },
116 {
117 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
118 loader: 'url-loader'
119 },
120]
121```
122
123## License
124
125MIT
Note: See TracBrowser for help on using the repository browser.