cipherdevgroup / cipher-theme-config

Grunt configuration for Cipher themes
MIT License
8 stars 4 forks source link

postcss configurability #8

Open ctalkington opened 8 years ago

ctalkington commented 8 years ago

i've been going back and forth with a way to use grunt configs to fine tune the options of each postcss processor as the way it works now it can only be configured via functions and if i were to say want to change the rootValue for pxtorem (or disable for specific project), I have to do the following in my gruntfile.

function setPostCSSProcessors() {
    var parr = [];
    var plugins = grunt.config('postcss.options.plugins') || {};

    Object.keys(plugins).forEach(function(plugin) {
      if (plugins[plugin]) {
        var pluginFunc = require(plugin) || false;

        if (pluginFunc) {
          parr.push(pluginFunc(plugins[plugin] || {}));
        }
      }
    });

    grunt.config.set('postcss.options.processors', parr);
  };

  setPostCSSProcessors()

it would be possible to support something globally if load-project-config allowed passing options to load-grunt-config as theres postProcess option which would allow inherit and override as we get with other tasks but convert it to a processors array JIT

robneu commented 8 years ago

You can also override the config in the theme just by pulling the individual config into the theme's config dir and updating whatever values you need to change.

That said, I agree there really should be a better way to adjust PostCSS modules as we may end up using more of them in the future as things shift more and more away from preprocessors.

ctalkington commented 8 years ago

you actually can't do that reliably as load-grunt-config default merge will simply replace within arrays so you would need no-ops for every processor to avoid grunt-postcss throwing up.

ctalkington commented 8 years ago

ie

[ pixtorem(), autoprefixer() ] merged with
[ bananas() ] becomes 
[ bananas(), autoprefixer() ] 
robneu commented 8 years ago

Ahhh I see... that could probably get pretty screwy depending on what needed to be configured.

Maybe it would be worth opening an issue about this on load-project-config? I'm sure @bradyvercher would make whatever adjustments are necessary.

ctalkington commented 8 years ago

yah i think i will open issue regarding passing options to load-grunt-config from load-project-config because once again a way to override exists

// use different function to merge config files
mergeFunction: require('recursive-merge')
robneu commented 8 years ago

@ctalkington So now that this is merged in, what's the best method for handling this?

ctalkington commented 8 years ago

@robneu this is on my radar and will be messing with it a bit more in the upcoming week or so.