rollup-plugin-svg-import
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

rollup-plugin-svg-import

Import .svg images in javascript files

Installation

npm install --save-dev rollup-plugin-svg-import

Usage

By default SVG import returns a <svg> DOM node:

import icon from './icon.svg';

document.body.appendChild(icon());

To import SVG image as a string, e.g. for SSR, set stringify to true:

import icon from './icon.svg';

document.body.innerHTML += icon;

Configuration

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

export default {
  input: './input.js',
  output: {
    file: './output.js',
    format: 'esm',
  },
  plugins: [
    svg({
     /**
      * If `true`, instructs the plugin to import an SVG as string.
      * For example, for Server Side Rendering.
      * Otherwise, the plugin imports SVG as DOM node.
      */
      stringify: true
    }),
  ],
};

Readme

Keywords

Package Sidebar

Install

npm i rollup-plugin-svg-import

Weekly Downloads

14,332

Version

3.0.0

License

MIT

Unpacked Size

3.28 kB

Total Files

4

Last publish

Collaborators

  • korywka