Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Last active December 14, 2015 14:39
Show Gist options
  • Save jonschlinkert/5102394 to your computer and use it in GitHub Desktop.
Save jonschlinkert/5102394 to your computer and use it in GitHub Desktop.
Externalize options for the grunt-recess task. This works for other tasks as well.

We can move those options into an external JSON file, .recessrc, like this:

{
  "compile": true,
  "compress": false,
  "noIDs": true,
  "noJSPrefix": true,
  "noOverqualifying": true,
  "noUnderscores": true,
  "noUniversalSelectors": true,
  "zeroUnits": true,
  "strictPropertyOrder": true,
  "zeroUnits": true
}

grunt-recess

Just a demonstration for how to externalize options using grunt.file.readJSON(''). Here is the full list of options for grunt-recess (but this will work for other tasks as well).

recess: {
  dist: {
    options: {
      // Default
      compile             : true,   // Compiles CSS or LESS. Fixes white space and sort order.
      compress            : false,  // Compress your compiled code
      noIDs               : true,   // Doesn't complain about using IDs in your stylesheets
      noJSPrefix          : true,   // Doesn't complain about styling .js- prefixed classnames
      noOverqualifying    : true,   // Doesn't complain about overqualified selectors (ie: div#foo.bar)
      noUnderscores       : true,   // Doesn't complain about using underscores in your class names
      noUniversalSelectors: true,   // Doesn't complain about using the universal * selector
      prefixWhitespace    : true,   // Adds whitespace prefix to line up vender prefixed properties
      strictPropertyOrder : true,   // Complains if not strict property order
      stripColors         : false,  // Strip colors from the Terminal output
      // ^ Deprecated. Instead pass `--no-color` to grunt
      zeroUnits           : true    // Doesn't complain if you add units to values of 0
    },
    files: {
      'dist/combined.css': [
        'src/main.css',
        'src/component.css'
      ]
    }
  }
}

then change the options to this:

recess: {
  dist: {
    options: grunt.file.readJSON('.recessrc'),
    files: {
      'dist/combined.css': [
        'src/main.css',
        'src/component.css'
      ]
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment