Search code examples
htmlcsspostcss

Setting Up a config file for PostCSS


I'm using PostCSS and I want to add Post-uncss. I use no task runners, just Postcss-cli. My package.json looks like this right now:

"css-clean": "npx postcss src\\css\\main.css -u autoprefixer --replace && npx postcss src\\css\\main.css -u css-declaration-sorter --replace --no-map"

It's getting rather long. I saw mentioned that PostCSS can have a config file "postcss.config.js". The only thing mentioned in the article is the skeleton:

module.exports = {
    plugins: {
      'autoprefixer': {},
      'css-declaration-sorter': {}
    }
  };

The uncss documentation just says for options:

{
  html: ['index.html', 'about.html', 'team/*.html'],
  ignore: ['.fade']
}

I was hoping if someone has experience with using the config file to give some advice because I don't believe this feature is well documented.


Solution

  • You can pass plugin parameters within a postcss.config.js file like so:

    module.exports = {
        plugins: [
            require('module-name-1'),
            require('module-name-2')({
                option-a: 1,
                option-b: "quoted value",
            }),
        ],
     };