Skip to content

Instantly share code, notes, and snippets.

@miensol
Created July 1, 2013 19:08
Show Gist options
  • Save miensol/5903632 to your computer and use it in GitHub Desktop.
Save miensol/5903632 to your computer and use it in GitHub Desktop.
Grunt watching less and coffee Compiles individual files
var path = require('path');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
coffee: {
all: {
files: [{
src: ["lib/**/*.coffee"],
expand: true,
rename: function(destBase, destPath) {
return destPath.replace(".coffee", ".js");
}
}
]
},
changed: {
files: {}
}
},
less: {
all: {
files: [{
src: ["styles/**/*.less"],
expand: true,
rename: function(destBase, destPath) {
return destPath.replace(".less", ".css");
}
}
]
},
changed: {
files: {}
}
},
regarde: {
coffee: {
files: ["lib/**/*.coffee"],
tasks: ["coffee:changed"],
options: {
nospawn: true
}
},
less: {
files: ["styles/**/*.less"],
tasks: ["less:changed"],
options: {
nospawn: true
}
}
}
});
grunt.event.on('regarde:file', function onFileChange(change, type, filepath, other){
var filesConfig = {},
extension = path.extname(filepath).split('.'),
fileType = extension[extension.length - 1], targetFile;
if(fileType === 'coffee'){
targetFile = filepath.replace(".coffee",".js");
}
if(fileType === 'less'){
targetFile = filepath.replace(".less",".css");
}
filesConfig[targetFile] = filepath;
console.log(arguments);
grunt.config([fileType,'changed'], {
files: filesConfig
});
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-regarde');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment