npm i webpack-svgstore-plugin --save-dev
//webpack.config.js
var SvgStore = require('webpack-svgstore-plugin');
module.exports = {
entry: {
app: path.join(_path, 'platform', 'static', 'js', 'index.js'),
},
plugins: [
new SvgStore(
//=========> input path
[
path.join(sourcePath, 'svg', '**/*.svg'),
'!' + path.join(sourcePath, 'svg', 'excludeFolder', '**/*.svg'),
],
//=========> output path
'svg',
//=========> options
{
name: '[hash].sprite.svg',
chunk: 'app',
baseUrl: '//path-to-cdn:port/',
prefix: 'myprefix-',
template: path.join('root', 'templates', 'layout.jade'),
svgoOptions: {
plugins: [
{ removeTitle: true }
]
}
}
)
]
}
<svg class="svg-icon">
<use xlink:href="#icon-name"></use>
</svg>
- path to folder with svgs, use globby patterns
- path to output folder, begins with webpack
publicPath
name
- sprite namechunk
- add xhr to entry point chunk (optional)baseUrl
- server where the sprites are stored, for example a CDN (optional)prefix
- add prefix to svg id's (optional, default:'icon-'
)template
- add custom jade template layout (optional)svgoOptions
- options for svgo (optional, default:{}
)
NPM package available here: webpack-svgstore-plugin
MIT © Chernobrov Mike, Gordey Levchenko