nddery / webpack-svgstore-plugin

Simple svg-sprite creating with webpack

Home Page:https://www.npmjs.com/package/webpack-svgstore-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WEBPACK PLUGIN

███████╗██╗   ██╗ ██████╗     ███████╗████████╗ ██████╗ ██████╗ ███████╗
██╔════╝██║   ██║██╔════╝     ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
███████╗██║   ██║██║  ███╗    ███████╗   ██║   ██║   ██║██████╔╝█████╗  
╚════██║╚██╗ ██╔╝██║   ██║    ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝  
███████║ ╚████╔╝ ╚██████╔╝    ███████║   ██║   ╚██████╔╝██║  ██║███████╗
╚══════╝  ╚═══╝   ╚═════╝     ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝                                                                     

NPM

Package info

Build Status NPM version Code Climate Test Coverage

Installation

npm i webpack-svgstore-plugin --save-dev

We are not maintain version for node.js 0.12 more

Only:

  • "7.0+"
  • "6.0"
  • "4.0"

Webpack version support

Use webpack-svgstore-plugin@3.x.x for Webpack 1.x.x
Use webpack-svgstore-plugin@4.x.x for Webpack 2.x.x

Webpack configuration

EXAMPLE here

Usage

1) require plugin

//webpack.config.js
var path = require('path');
var SvgStore = require('webpack-svgstore-plugin');
module.exports = {
  plugins: [
    // create svgStore instance object
    new SvgStore({
      // svgo options
      svgoOptions: {
        plugins: [
          { removeTitle: true }
        ]
      },
      prefix: 'icon',
      path: path.join(__dirname, '../src/assets/**/*.svg')
    })
  ]
}

2) Put function mark at your chunk

// plugin will find marks and build sprite

var __svg__           = { path: './assets/svg/**/*.svg', name: 'assets/svg/[hash].logos.svg' };
// will overwrite to var __svg__ = { filename: "assets/svg/1466687804854.logos.svg" };

// also you can use next variables for sprite compile
// var __sprite__     = { path: './assets/svg/minify/*.svg', name: 'assets/svg/[hash].icons.svg' };
// var __svgstore__   = { path: './assets/svg/minify/*.svg', name: 'assets/svg/[hash].stuff.svg' };
// var __svgsprite__  = { path: './assets/svg/minify/*.svg', name: 'assets/svg/[hash].1logos.svg' };

// require basic or custom sprite loader
require('webpack-svgstore-plugin/src/helpers/svgxhr')(__svg__);
Dear friends...

As you know, last version has integrated ajax sprite loader. Right now, you can override that. Or create your own sprite ajax loader function.

3) HTML code for happy using

HTML:

  <svg class="svg-icon">
    <use xlink:href="#icon-name"></use>
  </svg>

React JSX:

  <svg className='svg-icon'>
    <use xlinkHref='#icon-name' />
  </svg>

Plugin settings

options

  • template - add custom jade template layout (optional)
  • svgoOptions - options for svgo (optional, default: {})
  • path - absolute path to SVG files (optional, default: your function mark path or /**/*.svg)
  • name - name of the resulting file (optional, default: your function mark name or [hash].sprite.svg)

License

NPM package available here: webpack-svgstore-plugin

MIT © Chernobrov Mike, Gordey Levchenko

About

Simple svg-sprite creating with webpack

https://www.npmjs.com/package/webpack-svgstore-plugin


Languages

Language:JavaScript 97.4%Language:HTML 2.6%