Wondering what’s next for npm?Check out our public roadmap! »

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

    2.0.0 • Public • Published

    rollup-plugin-inline-svg

    Plugin for Rollup what transforms svg files into string on import.

    Build Status Coverage Status

    Installation

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

    OR

    yarn add --dev rollup-plugin-inline-svg

    Configuration

    // rollup.config.js
    import inlineSvg from 'rollup-plugin-inline-svg';
     
    export default {
      input: "src/input.js",
      output: "dist/output.js",
      plugins: [
        inlineSvg({
          // Removes specified tags and its children. You can specify tags by setting removingTags query array.
          // default: false
          removeTags: false,
      
          // warning: this won't work unless you specify removeTags: true
          // default: ['title', 'desc', 'defs', 'style']
          removingTags: ['title', 'desc', 'defs', 'style'],
         
          // warns about present tags, ex: ['desc', 'defs', 'style']
          // default: []
          warnTags: [], 
     
          // Removes `width` and `height` attributes from <svg>.
          // default: true
          removeSVGTagAttrs: true,
      
          // Removes attributes from inside the <svg>.
          // default: []
          removingTagAttrs: [],
      
          // Warns to console about attributes from inside the <svg>.
          // default: []
          warnTagAttrs: []
        })
      ],
    }

    Usage

      import svg from "...test.svg"
     
      document.getElementById("test").innerHTML = svg; // svg = "<svg...>...</svg>"

    Note: Do not forget to append .svg extension or it will try to resolve with .js (or use plugin for resolving extensions)

    This plugin is inspired by svg-inline-loader for webpack. I'm trying to make this plugin similar to the webpack one to make easier migration from webpack.

    License

    MIT, see LICENSE for more information.

    Install

    npm i rollup-plugin-inline-svg

    DownloadsWeekly Downloads

    1,214

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    32.5 kB

    Total Files

    21

    Last publish

    Collaborators

    • avatar