你如何看待多个文件,但只能在Grunt.js中运行更改文件的任务? [英] How do you watch multiple files, but only run task on changed file, in Grunt.js?
问题描述
在学习如何使用咕噜时,我正在尝试制作一个简单的咖啡脚本观察器/编译器。问题是,如果我告诉监视
任务来观看几个文件,并且一个文件发生了变化,它将把所有文件传递给咖啡
命令。这意味着当您更改1个文件时,它将重新编译与 src
模式匹配的所有文件。相反,我只想重新编译单个匹配 src
模式的文件。
这是 grunt.js
:
module.exports = function(grunt){
grunt.initConfig({
coffee:{
app:{
src:['test / cases / controller / *。coffee'],
dest:'tmp ',
选项:{
bare:true,
preserve_dirs:true
}
}
},
手表:{
文件:['< config:coffee.app.src>'],
tasks:['coffee:app']
}
});
grunt.loadNpmTasks('grunt-coffee');
grunt.registerTask('default','coffee');
};
这是使用 grunt-coffee ,这基本上是这样的: https://gist.github .com / 2373159 。
当我运行 grunt watch
时,我将文件保存在 test / cases / controller / *。coffee
,它编译匹配文件的所有(将它们放在 tmp / *
)。
您是如何使用grunt 编译已更改文件?
即将发布(目前正在开发中)v0.4.0a grunt拥有 grunt.file.watchFiles 对象,该对象专为此目的而设计。 grunt-coffee插件可能已经增加了对此功能的支持,我不确定。
无论哪种方式,如果您有兴趣尝试一个开发版本咕噜在你的项目中,看看我什么时候可以使用开发中的功能'X'? FAQ条目。
In learning how to use grunt, I am trying to make a simple coffee-script watcher/compiler. The problem is, if I tell the watch
task to watch several files, and one changes, it is going to pass all of the files to the coffee
command. This means when you change 1 file, it's going to recompile all of the files matching the src
pattern. Instead, I want to only recompile the single file that changed that matches the src
pattern.
Here is the grunt.js
:
module.exports = function(grunt) {
grunt.initConfig({
coffee: {
app: {
src: ['test/cases/controller/*.coffee'],
dest: 'tmp',
options: {
bare: true,
preserve_dirs: true
}
}
},
watch: {
files: ['<config:coffee.app.src>'],
tasks: ['coffee:app']
}
});
grunt.loadNpmTasks('grunt-coffee');
grunt.registerTask('default', 'coffee');
};
This is using grunt-coffee, which is basically this: https://gist.github.com/2373159.
When I run grunt watch
, and I save a file in test/cases/controller/*.coffee
, it compiles all of the matching files (putting them in tmp/*
).
How do you instead only compile the changed file using grunt?
The upcoming (and currently in-development) v0.4.0a grunt has the grunt.file.watchFiles object, which was designed expressly for this purpose. The grunt-coffee plugin may have added support for this feature already, I'm not sure.
Either way, if you're interested in trying an in-development version of grunt in your project, check out the When will I be able to use in-development feature 'X'? FAQ entry.
这篇关于你如何看待多个文件,但只能在Grunt.js中运行更改文件的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!