Skip to content

A rollup plugin JUST to transform SVG files to symobl strings, then you can freely handle them.

License

Notifications You must be signed in to change notification settings

fjc0k/rollup-plugin-svg-to-symbol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rollup-plugin-svg-to-symbol Travis

A rollup plugin JUST to transform SVG files to symobl strings, then you can freely handle them.

Webpack version: fjc0k/svg-to-symbol-loader

Install

# Yarn
yarn add rollup-plugin-svg-to-symbol -D

# npm
npm i rollup-plugin-svg-to-symbol -D

Usage

// rollup.config.js
const svgToSymbol = require('rollup-plugin-svg-to-symbol')

module.exports = {
  plugins: [
    svgToSymbol()
  ]
}
// sprite.js
import add from './svg/add.svg'
import close from './svg/close.svg'

export default [
  '<svg><defs>',
  add,
  close,
  '</defs></svg>'
].join('')

The default export just likes:

<svg>
  <defs>
    <symbol id="add">.....</symbol>
    <symbol id="close">.....</symbol>
  </defs>
</svg>

Options

  • extractId
    • Type: ({ name }) => id
    • Default: ({ filePath, name }) => name
    • Desc: Use the function to custom symbol id. The name is the SVG filename without the extension. e.g.
// rollup.config.js
svgToSymbol({
  extractId({ name }) {
    return `icon-${name}`
  }
})
import add from './svg/add.svg'
// the add likes:
// <symbol id="icon-add">...</symbol>
  • svgo

About

A rollup plugin JUST to transform SVG files to symobl strings, then you can freely handle them.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published