svg-to-symbol-loader
A webpack loader JUST to transform SVG files to symobl strings, then you can freely handle them.
Last updated 8 years ago by funch .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install svg-to-symbol-loader 
SYNC missed versions from official npm registry.

svg-to-symbol-loader Travis

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

JUST SUPPORT WEBPACK 4.

Rollup version: fjc0k/rollup-plugin-svg-to-symbol

Install

# Yarn
yarn add svg-to-symbol-loader -D

# npm
npm i svg-to-symbol-loader -D

Usage

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: 'svg-to-symbol-loader'
      }
    ]
  }
}
// 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.
// webpack.config.js
{
  extractId({ name }) {
    return `icon-${name}`
  }
}
import add from './svg/add.svg'
// the add likes:
// <symbol id="icon-add">...</symbol>
  • svgo

Current Tags

  • 1.1.3                                ...           latest (8 years ago)

6 Versions

  • 1.1.3                                ...           8 years ago
  • 1.1.2                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Total 22
Today 0
This Week 6
This Month 22
Last Day 0
Last Week 16
Last Month 0
Dependencies (2)
Dev Dependencies (7)

© 2010 - cnpmjs.org x YWFE | Home | YWFE