3.0.0 • Published 2 years ago

@classpert/svg-globaldefs-webpack-plugin v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

SVG Global defs Webpack Plugin

This webpack plugin reformats SVG files to pull all inner <symbol>-bound graphical objects and put them into a global <defs> tag. Per MDN documentation, <defs> tag is used to store graphical objects that can be referenced later (with an <use> tag, for example). They are not supposed to be rendered directly if they're inside <defs>. Ideally, all later-referenced graphical objects should be stored that way (it keeps your svg organized and saves memory, since many symbols may reference the same object). However, browsers for the most part render svgs correctly even if there's no such organization effort. Unfortunately, that's not the case for Firefox. This plugin mostly remedies this issue.

Compatibility
This plugin is currently only compatible with webpack ^4.0.0.

Installation

npm install svg-globaldefs-webpack-plugin --save-dev

Usage

Webpack configuration

const path = require('path');
const SVGGlobalDefsWebpackPlugin = require('svg-globaldefs-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new SVGGlobalDefsWebpackPlugin({
      files: [ 
        path.resolve(__dirname, 'svgs/icons/*.svg'), 
        path.resolve(__dirname, 'svgs/sprite.svg')
      ],
      options: {
        attributes: ['linearGradient', 'mask', 'clipPath']
      }      
    })
  ]
}

Testing

npm test

License

This project is licensed under the MIT license.

3.0.0

2 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.0

4 years ago

2.0.1

4 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago