1. @svgr/rollup
SVGR Rollup plugin.
@svgr/rollup
Package: @svgr/rollup
Created by: gregberge
Last modified: Tue, 15 Aug 2023 06:46:24 GMT
Version: 8.1.0
License: MIT
Downloads: 1,039,419
Repository: https://github.com/gregberge/svgr

Install

npm install @svgr/rollup
yarn add @svgr/rollup

@svgr/rollup

Build Status
Version
MIT License

Rollup plugin for SVGR.

npm install @svgr/rollup --save-dev

In your rollup.config.js:

 {
  plugins: [svgr()]
}

In your code:

 import Star from './star.svg'

const App = () => (
  <div>
    <Star />
  </div>
)

Passing options

 {
  plugins: [svgr({ native: true })]
}

Using with url plugin

It is possible to use it with url.

In your rollup.config.js:

 {
  plugins: [url(), svgr()]
}

In your code:

 import starUrl, { ReactComponent as Star } from './star.svg'

const App = () => (
  <div>
    <img src={starUrl} alt="star" />
    <Star />
  </div>
)

The named export defaults to ReactComponent, but can be customized with the namedExport option.

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.

If you prefer named export in any case, you may set the exportType option to named.

Use your own Babel configuration

By default, @svgr/rollup applies a babel transformation with optimized configuration. 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.

 {
  plugins: [svgr({ babel: false })]
}

License

MIT

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code