A webpack
/sass-loader
plugin that provides SASS functions to automatically generate SVG spritesheet.
You can install the package using npm
or you can also clone this package.
npm install --save-dev webpack-sass-svg
Depending on your project setup, you can either add the following to your package.json
or webpack.config.js
.
This requires you to have installed and use sass-loader
.
const SVGSpriteSheetPlugin = require('webpack-sass-svg');
module.exports = {
// ... other config
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
'sass-loader' // sass-loader should be defined
],
},
],
},
plugins: [
// ... other plugins
new SVGSpriteSheetPlugin( '___PATH_TO_COMPILE_DIR___' )
],
};
After setting up webpack
, you can now use the SASS functions in your .sass
/.scss
files.
$spritesheet: SVGSpriteMap("../assets/svg-sprite/**/*.svg");
.svg-sprite {
background-image: $spritesheet;
background-size: SVGSpriteWidth($spritesheet) SVGSpriteHeight($spritesheet);
background-repeat: no-repeat;
}
.svg-circle {
width: SVGFileWidth($spritesheet, 'circle');
height: SVGFileHeight($spritesheet, 'circle');
background-position: SVGFilePosition($spritesheet, 'circle', 'relative');
}
- Add tests
- Use Typescript