Created
July 1, 2013 19:08
-
-
Save miensol/5903632 to your computer and use it in GitHub Desktop.
Grunt watching less and coffee Compiles individual files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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