1. rollup-plugin-svg
Import SVG images
rollup-plugin-svg
Package: rollup-plugin-svg
Created by: antony
Last modified: Sun, 26 Jun 2022 14:02:07 GMT
Version: 2.0.0
License: MIT
Downloads: 116,969
Repository: https://github.com/antony/rollup-plugin-svg

Install

npm install rollup-plugin-svg
yarn add rollup-plugin-svg

rollup-plugin-svg

Import SVG files as base64, or as Markup

CircleCI JavaScript Style Guide

Installation

 npm i -D rollup-plugin-svg

Usage

 // rollup.config.js
import svg from 'rollup-plugin-svg'

export default {
  entry: 'src/input.js',
  dest: 'dist/output.js',
  plugins: [
    svg()
  ]
}

You can then use svgs in your bundle thusly:

 import logo from './desirable-objects.svg'

// Without base64:
document.body.appendChild( logo )

// With base64:
<img src="{logo}" alt="Whatever" />

Options:

base64

Defaults to false.

Bas64 encoded SVGs will be 33% larger than the size on disk. You should therefore only use this for small images where the convenience of having them available on startup (e.g. rendering immediately to a canvas without co-ordinating asynchronous loading of several images) outweighs the cost.

Sources

This plugin was built (based on the rollup-plugin-image plugin) because it appears that the two existing suitable plugins:

rollup-plugin-image
rollup-plugin-url

don't seem to work any more. I wanted a simple solution to provide SVG images to Vudash

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