I'm using grunt-contrib-less and grunt-contrib-watch together. My less task uses the files array format to define multiple src and dest's. I'd like to reference those same files from the watch task. Like this:
grunt.initConfig({
less: {
build: {
files: [
{src: 'src/aa.less', dest: 'dest/a.css'},
{src: 'src/aa1.less', dest: 'dest/a1.css'}
]
}
},
watch: {
less: {
files: '<%= less.build.files %>',
tasks: ['less']
}
}
});
That underscore template works, but watch can't process the files array format, it only accepts file input as a string or array of strings. Here's what I've tried:
'<%= less.build.files.src %>'
doesn't work because less.build.files is an array, not an object.'<%= _(less.build.files).pluck("src").value() %>'
doesn't work, because even though it makes the right file list, it resolves to single string'src/aa.less,src/aa1.less'
, not an array.'{<%= _(less.build.files).pluck("src") %>}'
does work, as suggested here https://stackoverflow.com/a/21608021/490592, but it doesn't feel right. I'm trying to target a specific set of files, not pattern match from my whole project directory.grunt.config.set('watch.less.files', _(grunt.config.get('less.build.files')).pluck('src').value());
works, but this must be separate from the initConfig.
Is there a more elegant way to accomplish this?