Code Monkey home page Code Monkey logo

rollup-plugin-svg-to-symbol's Introduction

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

rollup-plugin-svg-to-symbol's People

Contributors

fjc0k avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wizzzout

rollup-plugin-svg-to-symbol's Issues

Error: Could not resolve svg

Hello,I am using your rollup plugin follow the readme, like this:
image

image

and create a file named icon.svg.ts
image

and import in AppComponent
image

but when I ngc project and rollup -p , an error occurs:
[!] Error: Could not resolve './svg/logo.svg' from out-tsc\app\projects\rocketbot\src\assets\icon.svg.js Error: Could not resolve './svg/logo.svg' from out-tsc\app\projects\rocketbot\src\assets\icon.svg.js
Do you know how to solve the problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.