SVG Plugin for rollupjs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
CHANGELOG.md
README.md
package.json
rollup.config.js
yarn.lock

README.md

rollup-plugin-svg

Import SVG files

Installation

yarn add rollup-plugin-svg --dev

Usage

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

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

You can use svgs in your bundle thusly:

import logo from './desirable-objects.svg'
document.body.appendChild( logo )

SVGs are encoded using base64, which means they 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