# react-svg-loader

> Optimize svg and load it as a React Component

Latest version **3.0.3** (published 2019-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-svg-loader
pnpm add react-svg-loader
yarn add react-svg-loader
bun add react-svg-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2019-06-03 |
| First published | 2015-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 2 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 637 |
| Author | boopathi |
| Maintainers | boopathi |
| Keywords | loader, react, react-svg-loader, webpack, webpack-loader |

## Links

- npm: https://www.npmjs.com/package/react-svg-loader
- Repository: https://github.com/boopathi/react-svg-loader
- Homepage: https://github.com/boopathi/react-svg-loader/tree/master/packages/react-svg-loader
- Issues: https://github.com/boopathi/react-svg-loader/issues
- npm.io page: https://npm.io/package/react-svg-loader

## Dependencies (2)

- [loader-utils](https://npm.io/package/loader-utils.md) ^1.2.3
- [react-svg-core](https://npm.io/package/react-svg-core.md) ^3.0.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.0.3 (latest) — 2019-06-03
- 3.0.4-alpha.3 (canary) — 2019-07-11
- 2.0.0-alpha.3 (alpha) — 2017-09-28
- 1.0.0-3 (beta) — 2016-04-08
- 3.0.4-alpha.2 — 2019-06-12
- 3.0.2 — 2019-06-01
- 3.0.2-alpha.2 — 2019-06-01
- 3.0.2-alpha.1 — 2019-05-31
- 3.0.1 — 2019-05-06
- 3.0.0 — 2019-05-03
- 2.1.1-alpha.36 — 2019-02-13
- 2.2.0-alpha.90436959 — 2018-03-17
- 2.2.0-alpha.b8e3c6d5 — 2018-02-28
- 2.2.0-alpha.02daccb2 — 2018-02-22
- 2.2.0-alpha.10f9a762 — 2018-01-05
- … 25 more at https://npm.io/package/react-svg-loader/versions

## README

# react-svg-loader

## Install

```sh
npm i react-svg-loader --save-dev
```

or

```sh
yarn add react-svg-loader --dev
```

## Usage

```js
// without webpack loader config
import Image1 from 'react-svg-loader!./image1.svg';

// or if you're passing all .svg files via react-svg-loader,
import Image2 from './image1.svg';

// and use it like any other React Component
<Image1 width={50} height={50}/>
<Image2 width={50} height={50}/>
```

### Loader output

By default the loader outputs ES2015 code (with JSX compiled to JavaScript using babel-preset-react). You can combine it with [babel-loader](https://github.com/babel/babel-loader) + [babel-preset-env](https://github.com/babel/babel-preset-env) to compile it down to your target.

```js
// In your webpack config
{
  test: /\.svg$/,
  use: [
    {
      loader: "babel-loader"
    },
    {
      loader: "react-svg-loader",
      options: {
        jsx: true // true outputs JSX tags
      }
    }
  ]
}
```

### SVGO options

```js
{
  test: /\.svg$/,
  use: [
    "babel-loader",
    {
      loader: "react-svg-loader",
      options: {
        svgo: {
          plugins: [
            { removeTitle: false }
          ],
          floatPrecision: 2
        }
      }
    }
  ]
}
```

## Internals

<p align="center">
Input SVG
</p>
<p align="center">↓</p>
<p align="center">
SVG Optimize using <a href="https://github.com/svg/svgo">SVGO</a>
</p>
<p align="center">↓</p>
<p align="center">
Babel Transform with <code>preset=react</code> and <a href="https://github.com/boopathi/react-svg-loader/tree/master/packages/babel-plugin-react-svg"><code>plugin=svgToComponent</code></a>
</p>

## Assumptions and Other gotchas

+ Root element is always `<svg>`
+ SVG is optimized using SVGO

## LICENSE

[MIT](https://github.com/boopathi/react-svg-loader/blob/master/LICENSE)

---
_Source: https://npm.io/package/react-svg-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
