pirxpilot / postcss-cli

Simple CLI for postcss
175 stars 17 forks source link

Load config from `postcss.config.js` #58

Open sntran opened 4 years ago

sntran commented 4 years ago

For those of us who is switching from the official postcss-cli to postcss-cli-simple, being able to reuse the existing postcss.config.js file is great, as we don't have to config our plugins again. Are you open to support that? The official one uses postcss-load-config under the hood, but it's kinda big, so I understand that you will not want to.

pirxpilot commented 4 years ago

Probably not - for context see some more info on the history of both projects. That said I am certainly open to a patch that exports the run module so that configuration can be read and prepared independently and passed to it. Do you want to experiment with that?

What are the differences between postcss.config.js that you ask about and what postcss-cli-simple expects in its -config option?

sntran commented 4 years ago

Thanks for the trouble making the change to run!

I came here because I don't like the bloats of the "official" postcss-cli, and I just need to be able to use postcss for autoprefixer in command line. I would try the new run.

What are the differences between postcss.config.js that you ask about and what postcss-cli-simple expects in its -config option?

For one, the exporting JSON format is different. Plugins are defined in plugins key instead of directly being in the root.

Secondly, the JS config file allows me to customize the plugins based on certain conditions. For example, autoprefixer with different browserlist setting.

Mostly, it's the consistency, so that users can switch between postcss-cli-simple and postcss-cli any time they want to.

I'm fine with you not supporting it. I'm sure I can do some renaming :)

Thanks for being open about it!

sntran commented 3 years ago

Circling back to this. It looks like your JS configuration format is not very different from postcss.config.js, except that plugins' configuration is placed under plugins map instead.

postcss-cli-simple syntax:

module.exports = {
  "postcss-url": {
    url: function(url) { return "http://example.com/" + url; }
  },
  autoprefixer: {
    browsers: "> 5%"
  }
};

postcss.config.js syntax:

module.exports = {
  plugins: {
    require('postcss-import'),
    require('tailwindcss'),
    autoprefixer: {
      browsers: "> 5%"
    },
  },
}

I think, at the very least, we can add support to plugins map for postcss-cli-simple. It also separates plugin configuration from command line arguments.

If you're ok with that, I can work on it.