I confirmed that grunt-contrib-watch does not support the files array format. I settled on using the grunt-config-set
technique I mentioned above.
Even though watch doesn't support the files array format, I make sure my custom tasks are compatible with it so I don't have to use the workarounds from my question. I've attached an example. For read-only tasks, I add a useDest
option, so they can be configured to operate on dest's instead of src's. This helps when you want to "pipe" one task into another task.
module.exports = function (grunt) {
grunt.registerMultiTask('example', 'Example read-only task', function () {
var options = this.options({
useDest: false, // When true, operate on dest files, instead of src
});
files = this.files.map(function (file) {
return { src: (options.useDest) ? [file.dest] : file.src }
});
files.forEach(function (file) {
grunt.log.writeln('Source: ' + grunt.log.wordlist(file.src));
});
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.initConfig({
concat: {
build: {
files: [
{ src: 'node_modules/grunt/lib/grunt/*.js', dest: 'lib.js' },
{ src: 'node_modules/grunt/internal-tasks/*.js', dest: 'tasks.js' }
]
}
},
example: {
build: {
options: {
useDest: true
},
files: '<%= concat.build.files %>'
}
}
});
};
The task will output:
Running "example:build" (example) task
Source: lib.js
Source: tasks.js