我想知道是否可以配置一个监视任务来监视两个不同的文件夹,并在每个文件夹上执行不同的任务。例如,只要有什么改变是/folder1,那么就应该执行task1,每当在/folder2中改变了什么,那么就应该执行task2。
文件夹结构的格式如下: root |-folder1 |-folder2
发布于 2014-06-16 17:04:40
如果您希望监视任务同时运行。在How to run two grunt watch tasks simultaneously这里有一个由RobW提供的很好的解决方案
我花了一些时间找到解决方案,下面是该解决方案的代码片段。
在自定义任务中动态编写配置对象是可行的。
grunt.registerTask('watch:test', function() {
// Configuration for watch:test tasks.
var config = {
options: {
interrupt: true
},
unit: {
files: [
'test/unit/**/*.spec.coffee'
],
tasks: ['karma:unit']
},
integration: {
files: [
'test/integration/**/*.rb',
'.tmp/scripts/**/*.js'
],
tasks: ['exec:rspec']
}
};
grunt.config('watch', config);
grunt.task.run('watch');
});
发布于 2014-05-09 16:33:26
最好的也是唯一有效的解决方案是:https://npmjs.org/package/grunt-focus添加这个插件,然后:
focus: {
sources: {
include: ['js', 'html', 'css', 'grunt']
},
testu: {
include: ['js', 'html', 'css', 'testu', 'grunt']
},
testi: {
include: ['js', 'html', 'css', 'testu', 'testi', 'grunt']
}
},
watch: {
js: {
files: paths.js,
tasks: ['jshint'],
options: {
livereload: true
}
},
html: {
files: paths.html,
options: {
livereload: true
}
},
css: {
files: paths.css,
tasks: ['csslint'],
options: {
livereload: true
}
},
testu: {
files: ['test/**/*.js', 'test/**/*.css'],
tasks: ['mochaTest'],
options: {}
},
testi: {
files: ['test/**/*.js', 'test/**/*.css'],
tasks: ['exec:cleanTestDB', 'protractor_webdriver', 'protractor'],
options: {}
},
grunt: {
files: ['Gruntfile.js', 'server/config/env/*.js'],
options: {
reload: true
}
}
}
然后,您可以方便地使用focus:sources或focus:testu。
JM。
https://stackoverflow.com/questions/13833196
复制相似问题