Postcss - color function plugin - “Unable to parse color from string”

依然范特西╮ 提交于 2021-02-17 05:30:15

问题


Using the following postcss plugins:

  • postcss-cssnext
  • postcss-nested
  • postcss-color-function

I constantly hit the following error, when using the following color function.

Unable to parse color from string "l(-20%)"

styles.css

@import 'variables.css';
//          ^-- contains: --blue: #3892e0;

& a {
    color: color(var(--blue), l(-20%));
    &:hover {
        color: color(var(--blue), l(0%));
    }
}

Webpack 2 snippet

{
    loader: 'postcss-loader',
    options: {
        plugins: [
            cssImport({ path: './src' }),
            cssnext({ browsers: ['last 2 versions'] }),
            colorFunction(),
            nested(),
        ],
    }
}

回答1:


The error, although not descriptive, is indicating that the , is unneeded. This follows future CSS (proposed) spec, but can be a nasty habit to drop if you come from any other language.

The solution is simply to remove the ,'s:

& a {
    color: color(var(--blue) l(-20%));
    &:hover {
        color: color(var(--blue) l(0%));
    }
}


来源:https://stackoverflow.com/questions/42324579/postcss-color-function-plugin-unable-to-parse-color-from-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!