Vit*_*kov 58 gruntjs grunt-contrib-watch
是否可以同时运行两个监视任务?
我知道我可以在手表设置中拥有任何我想要的任务,只需启动grunt手表,它就会观看所有这些,就像这样
...
watch: {
A: {
files: "js/dev/**/*.coffee",
tasks: ["coffee", "requirejs"]
},
B: {
files: "js/dev/**/*.coffee",
tasks: ["coffee"]
},
C: {
files: "js/dev/**/*.html",
tasks: ["copy"]
}
}
...
Run Code Online (Sandbox Code Playgroud)
......但我不需要这个.我只想拥有不同的开发和生产任务.你可以猜到,A(生产)和B(开发)之间的唯一区别是缩小和连接.我不需要同时启动A和B任务.
首先,我提出了这个想法
grunt.registerTask("prod", ["watch:A", "watch:C"]);
grunt.registerTask("dev", ["watch:B", "watch:C"]);
Run Code Online (Sandbox Code Playgroud)
但这没效果.只是第一次观察任务正在运行(C永远不会起作用).这可能做我想要的吗?
Nic*_*ery 74
我发现使用grunt-concurrent工作:
concurrent: {
options: {
logConcurrentOutput: true
},
prod: {
tasks: ["watch:A", "watch:C"]
},
dev: {
tasks: ["watch:B", "watch:C"]
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
grunt.registerTask("prod", ["concurrent:prod"]);
grunt.registerTask("dev", ["concurrent:dev"]);
Run Code Online (Sandbox Code Playgroud)
Rob*_*obW 18
编辑:并发现在有一个logConcurrentOutput选项!更多信息:https://github.com/sindresorhus/grunt-concurrent#logconcurrentoutput.
Watch是一个奇怪的并发但阻塞的任务,因此您必须具有创造性才能使多任务类功能正常工作.
并发丢失了监视任务的所有输出,这并不理想.
尝试在自定义任务中动态编写配置对象:
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');
});
Run Code Online (Sandbox Code Playgroud)
jmc*_*n92 11
有最好和唯一可行的解决方案: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
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后你使用焦点:来源或焦点:testu作为您的方便.
JM.
grunt-concurrent或grunt-focus都是很好的解决方案,但它们都破坏了livereload功能.
我的解决方案是动态组合手表配置,假设您不会同时运行这两种配置.
你可以做这样的事情
grunt.config.merge({
watch: {
options: {
livereload: true
},
C: {
files: "js/dev/**/*.html",
tasks: ["copy"]
}
}
});
grunt.registerTask('watch-forProd', function () {
grunt.config.merge({
watch: {
A: {
files: "js/dev/**/*.coffee",
tasks: ["coffee", "requirejs"]
}
}
});
grunt.task.run('watch');
});
grunt.registerTask('watch-forDev', function () {
grunt.config.merge({
watch: {
B: {
files: "js/dev/**/*.coffee",
tasks: ["coffee"]
}
}
});
grunt.task.run('watch');
});
grunt.registerTask("prod", ["watch-forProd"]);
grunt.registerTask("dev", ["watch-forDev"]);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31858 次 |
| 最近记录: |