Back to results
antony/rollup-plugin-svg(opens in a new tab)
Language: JavaScript
SVG Plugin for rollupjs
- stars
- 29
- watchers
- 1
- forks
- 5
- open issues
- 7
- Last updated
- 11/17/2022
Language: JavaScript
SVG Plugin for rollupjs
Import SVG files as base64, or as Markup
npm i -D rollup-plugin-svg
// 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" />
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.
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
MIT