I currently have some code that watches for changes in .less files. However I would like to print out there file path, so that at a later date I will be able to add this to a log file.
grunt.initConfig({
watch: {
less: {
files: ['vendor/*.less'],
tasks: ['lessTask'],
options: {
spawn: false,
interrupt: true,
},
},
},
});
grunt.registerTask('lessTask', function(filepath){
grunt.log.writeln(filepath + ': has changed');
//Compile less files to CSS
//Run acceptance tests for UI changes
});
My question is how do I pass over the 'filepath' argument?
With every Grunt task there is a property called filter
which is intended to use a callback to filter out certain file paths. But it will give you the file path of each file fed to a task:
grunt.initConfig({
less: {
target: {
src: 'vendor/*.less',
dest: 'dist/style.css',
filter: function(filepath) {
grunt.log.writeln(filepath + ' fed to less task');
return true;
},
},
},
});
Otherwise if you would like to know which file was changed by the watch
task; it has a watch
event:
grunt.event.on('watch', function(action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
});