-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to use CSS variables together with svg-transform-loader? #71
Comments
Yes, it's possible. You'll need to use postcss-move-props-to-bg-image-query plugin and configure .postcssrc.js module.exports = {
plugins: [
require('postcss-css-variables')(),
require('postcss-move-props-to-bg-image-query')({
computeCustomProps: require('postcss-css-variables')()
})
]
}; It's not documented feature so in a few days I'll add it to the docs :) |
Thanks for your help, but this solution has one big downside: it requires the whole CSS to be passed through If I omit the module.exports = {
plugins: [
require('postcss-move-props-to-bg-image-query')({
computeCustomProps: require('postcss-css-variables')()
})
]
}; Then I get the following error:
Is there any way to make |
I didn't test |
I was referring to the code snippet you posted before: module.exports = {
plugins: [
require('postcss-css-variables')(),
require('postcss-move-props-to-bg-image-query')({
computeCustomProps: require('postcss-css-variables')()
})
]
}; At the 3rd line you import the 'postcss-css-variables' plugin. If I do so then everything works fine - the CSS variables are transformed when used together with The problem is that I don't want to pass my entire CSS through 'postcss-css-variables' because it replaces all my CSS variables with their strings representations - which I'd like to avoid. The following code doesn't work: module.exports = {
plugins: [
require('postcss-move-props-to-bg-image-query')({
computeCustomProps: require('postcss-css-variables')()
})
]
}; It causes an error I posted before.
Sure, I'll do it soon. Thanks for your help! |
@wujekbogdan ping |
@kisenka |
@wujekbogdan ping |
Ok, I figured how to make this work. import postCSSCustomProperties from 'postcss-custom-properties';
import moveProps from 'postcss-move-props-to-bg-image-query'; moveProps({
computeCustomProps: postCSSCustomProperties({ preserve: false }).Once,
}) :root {
--bookmark-color: green;
}
.bookmark {
background-image: url(../images/assets/bookmark.svg);
-svg-mixer-fill: var(--bookmark-color);
background-repeat: no-repeat;
background-position: center;
} |
It doesn't work with postcss-custom-properties 12+ because of changes in the PostCSS 8 API. Also I had to write this to make it work again: import postcss from 'postcss';
import postCSSGlobalData from '@csstools/postcss-global-data';
import postCSSCustomProperties from 'postcss-custom-properties';
import moveProps from 'postcss-move-props-to-bg-image-query'; moveProps({
computeCustomProps: root => postcss([
postCSSGlobalData({
files: ['path/to/global-variables.css'],
}),
postCSSCustomProperties({ preserve: false }),
]).process(root),
}) |
When I do the following:
then
var(--my-custom-color-1)
is not evaluated to an actual color.I thought that maybe I could use the
transform
callback together with postcss-css-variables, but it's not possible because the CSS file is not available within the context of this callback.I tried to modify the plugin to be able to access the
Declaration
object and transform CSS variables into strings withpostcss-css-variables
, but I got stuck at processing CSS variables MadLittleMods/postcss-css-variables#106The text was updated successfully, but these errors were encountered: