问题
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