Answer the question
In order to leave comments, you need to log in
How to attach SASS variable to background SVG (using Webpack)?
Hey!
Friends, I ask for help.
I have file.svg.
There is CSS (SASS):<svg fill="$main-color" ... </svg>
$main-color: red;
.item {
background: url('file.svg');
}
Answer the question
In order to leave comments, you need to log in
In general, he asked - he answered.
This is done like this:
install npm install svg-fill-loader --save
1. in the webpack config, write the rule for svg:
{
test: /\.svg((\?.*)?|$)/,
loaders: [
'url-loader',
'svg-fill-loader?selector=.svg-fill' // `selector` option will be used for all images processed by loader
]
},
$main-color: red;
@mixin apply-background-image($url, $color) {
$base-color: str-slice(inspect($color), 2);
background-image: unquote('url("' + $url + "?fill=%23" + $base-color +'")');
}
item {
@include apply-background-image("./../assets/svg/item.svg", $main-color);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question