nDmitry / grunt-postcss

Apply several post-processors to your CSS using PostCSS.
MIT License
419 stars 57 forks source link

Multiple task with multiple options and dynamically expanded targets #93

Closed davidetruffo closed 8 years ago

davidetruffo commented 8 years ago

Hello,

I'm trying to use your plugin (which btw is really promising :)) to make a couple of things with my scss files. The problem i'm having is in the configuration, as i'd love to have different tasks, with different options, and different target files. Specifically, the target files would be dynamically expanded (not sure it the term is correct, but the link should help to clarify what i mean :) ) (it works fine with a single task, but i'd need different tasks with different plugins and targets)

here's my chunk of code (please note that s.src_scc and stuff like that are just variables to have paths in a separate file) (brackets are missing 'cause it's coffeescript):

module.exports =
  comb:
    options:
      syntax: require('postcss-scss')
    processors: [
      require('postcss-sorting')({
        'sort-order': 'default',
        'empty-lines-between-children-rules': 3
      })
    ]
    app:
      files: [
        expand: true,
        cwd: s.src_css + '/<%= pkg.name %>/',
        src: '**/*.' + s.src_css,
        dest: s.src_css + '/<%= pkg.name %>/'
      ]

    bootstrap:
      files: [
        expand: true,
        cwd: s.src_css + '/bootstrap/',
        src: '**/*.' + s.src_css,
        dest: s.src_css + '/bootstrap/'
      ]

  prefix:
    options:
      syntax: require('postcss-scss')
    processors: [
      require('autoprefixer')({
        browsers: 'last 2 versions'
      })
    ]
    app:
      files: [
        expand: true,
        cwd: s.src_css + '/<%= pkg.name %>/',
        src: '**/*.' + s.src_css,
        dest: s.src_css + '/<%= pkg.name %>/'
      ]

My files are in scss/[pkg.name]/file_name.scss in the root. Id like to be able to call grunt postcss:comb:app to sort some files and grunt:postcss:comb:bootstrap to sort other files, as well as run grunt postcss:prefix:app to use a different plugin on a different set of target files. I've spent my day reading old issues, blogs, Q&As etc, and from my understanding it is possible to do so. What am i doing wrong?

Output in console is:

...
Loading "postcss.js" tasks...OK
+ postcss

Running "postcss:comb:app" (postcss) task
Verifying property postcss.comb exists in config...OK
File: [no files]
Options: processors=[], map=false, diff=false, safe=false, failOnError=false, writeDest, syntax={}

Done.

Thanks! d.

toptalo commented 8 years ago

Need too

nDmitry commented 8 years ago

If I understand correctly, you should declare an alias task that will run other tasks in the config in the order you want: http://gruntjs.com/creating-tasks#alias-tasks