Grunt task to lint and minify CSS and LESS, using the Twitter RECESS module:
Developed at Twitter to support our internal styleguide, RECESS is a simple, attractive code quality tool for CSS built on top of LESS.
Incorporate it into your development process as a linter, or integrate it directly into your build system as a compiler, RECESS will keep your source looking clean and super manageable.
Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-recess
Then add this line to your project's grunt.js
gruntfile:
grunt.loadNpmTasks('grunt-recess');
This grunt task is a multi task, which means you can specify multiple subtasks and grunt will iterate over them. The dist
below is a subtask, you could e.g. create a dev
subtask to handle stuff while developing.
recess: {
dist: {
src: ['src/main.css']
}
}
recess: {
dist: {
src: ['src/main.less'],
dest: 'dist/main.css',
options: {
compile: true
}
}
}
dest
is only needed when compile: true
, it won't output any warnings in this mode.
You can also specify .less
files and they will be compiled.
recess: {
dist: {
src: [
'src/main.css',
'src/component.css'
],
dest: 'dist/combined.css',
options: {
compile: true
}
}
}
You can specify more than one src
to concat the files.
// Default
compile: false // 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
zeroUnits: true // Doesn't complain if you add units to values of 0
Grunt currently doesn't have a way to test tasks directly. You can test this task by running grunt
and check that it passes on the valid files and fails on the invalid.
In lieu of a formal styleguide, take care to maintain the existing coding style.
MIT License (c) Sindre Sorhus