An open API service indexing awesome lists of open source software.

https://github.com/jaredlunde/snowpack-plugin-svgr

Use svgr to transform your SVGs into React components with Snowpack
https://github.com/jaredlunde/snowpack-plugin-svgr

snowpack snowpack-plugin snowpack-svgr svgr

Last synced: 10 months ago
JSON representation

Use svgr to transform your SVGs into React components with Snowpack

Awesome Lists containing this project

README

          


# snowpack-plugin-svgr

> Use [svgr](https://github.com/gregberge/svgr) to transform your SVGs into React components with Snowpack

```sh
npm i -D snowpack-plugin-svgr
```



Types


Code coverage


Build status


NPM Version


MIT License

---

## Quick start

```js
// snowpack.config.json
{
"plugins": [["snowpack-plugin-svgr", { /* see "Plugin Options" below */ }]]
}
```

#### Plugin Options

```typescript
interface SnowpackPluginSvgrOptions {
/**
* Includes only the specified paths
*/
include?: string[]
/**
* Excludes the specified paths
*/
exclude?: string[]
/**
* These options are passed directly to babel.transformAsync()
*/
babelOptions?: TransformOptions
/**
* These options are passed directly to `@svgr/core`'s `convert()` function
* See: https://react-svgr.com/docs/options/
*/
svgrOptions?: any
}
```

## Usage

```js
import CatIcon from './assets/icons/cat.svg'

// Use like you would an `` component

```

#### Adding types to a TypeScript app

In `types/static.d.ts`

```typescript
// Replace this
declare module '*.svg' {
const ref: string
export default ref
}

// With this
declare module '*.svg' {
const ref: React.RefForwardingComponent<
SVGSVGElement,
React.SVGAttributes
>
export default ref
}
```

## LICENSE

MIT