@unger1984/webpack-svgstore
v0.1.1
Published
Svgstore plugin for Webpack 5
Downloads
95
Maintainers
Readme
@unger1984/webpack-svgstore
This package is a modification of the original package from David Bergmann
Combine svg files into one with <symbol>
elements. Read more about this in CSS Tricks article. This plugin was built for Webpack 5. It takes some ideas from webpack-svgstore-plugin and gulp-svgstore.
Install
npm i -D @unger1984/webpack-svgstore
Usage
1) Require the plugin in your webpack.config.js file
//webpack.config.js
const SvgStore = require("@unger1984/webpack-svgstore");
module.exports = {
plugins: [
// create svgStore instance object
new SvgStore({
path: path.resolve(__dirname, "assets/svg/**/*.svg"),
fileName: "svg-sprites.svg",
prefix: "icon-",
}),
],
};
2) Add the sprites loader in your code
import svgxhr from "@unger1984/webpack-svgstore/dist/helpers/svgxhr";
svgxhr("svg-sprites.svg");
3) HTML code for using your icons
HTML:
<svg>
<use xlink:href="#icon-name"></use>
</svg>
JSX:
<svg>
<use xlinkHref="#icon-name" />
</svg>
Plugin Options
| Name | Type | Default | Description |
| :-----------------: | :-----------: | :---------------: | :--------------------------------------------------------------------------------------------------------------------------- |
| path
| {String}
| /**/*.svg
| This option determines the path to the svg files that are going to be included in the sprites file. |
| fileName
| {String}
| svg-sprites.svg
| This option determines the name of the resulting sprites file. |
| inlineSvg
| {Boolean}
| false
| This option determines if the output should only contain the <svg>
element without <?xml ?>
and DOCTYPE
to use inline. |
| removeViewBox
| {Boolean}
| false
| Allows removing the viewBox attribute from each element. |
| prefix
| {String}
| icon-
| This option determines the prefix of each symbol's id . |
License
NPM package available here: webpack-svgstore
MIT © Unger Andrey