This is my Webpack
configs for scss/css
files.
...
{
test: /\.s?css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 2 } },
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: loader => [
require('postcss-import')({ root: loader.resourcePath }),
require('cssnano')(),
require('postcss-cssnext')(),
]
}
},
'sass-loader',
]
}
...
The problem is that when I use cssnext
functions like gray(100)
, the output CSS
file has an empty value where the function was placed. I would like to know what I did wrong here.
i.e.
background-color: gray(100);
outputs to background-color: ;
I'm new to postcss so I don't really know how it works or how to configure it properly as of yet.
For your exact problem, the
cssnext
functions, you must putcssnano
afterpostcss-cssnext
, like below:BUT I don't know, why did you use
sass-loader
? when you havepostcss
in your project.Actually
PostCSS
can do all jobs likesass
even better, it is up to you for syntax style, I suggest seeTHIS REPO
, it has complete configuration ofPostCSS
onWebpack
, also in this repo, theSCSS
syntax is used.For clearness I write a part of configuration below:
Even I use
*.pcss
instead of*.scss
,*.sass
or*.css
, it is just for consistency and no different.The
PostCSS
configuration is in separated file, it is:Absolutely
cssnext
works well, I usedcolor()
function and it works well.