我正在尝试使用grunt-contrib-watch和grunt-rsync将任何文件更改上传到我的开发服务器。这是我的设置:
var path = require('path');
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
...
watch: {
upload: {
files: ['*'],
},
...
},
rsync: {
options: {
args: ['--verbose'],
exclude: ['.*','node_modules','sql','artifacts','session','logs','cache'],
recursive: true,
syncDestIgnoreExcl: true
},
dev: {
options: {
src: './',
dest: '/usr/local/project',
host: 'dev3',
}
}
},
});
grunt.event.on('watch', function(action, filepath, target) {
if(target!=='upload') return;
grunt.config('rsync.dev.options.src', filepath);
grunt.task.run('rsync:dev');
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-rsync');
...
};
这项rsync
任务本身就很好。它相对较快地上传我的整个项目,但速度不够快,无法在每次文件编辑时运行。
我正在尝试在再次运行任务之前grunt.event.on
修改src
它,以便它只上传一个文件。grunt.task.run('rsync:dev')
然而,似乎根本没有做任何事情。不会出错,什么都没有。这是我运行它然后创建一个新文件时的输出:
$ grunt watch:upload --debug --stack
Running "watch:upload" (watch) task
Waiting...OK
>> File "ppp" added.
如果我给它一个无效的任务名称,它会出错,所以它显然正在寻找任务,我只是不确定它在做什么。该文件永远不会弥补我的服务器。
我怎样才能让它只同步我保存的文件?
NB newer似乎也不起作用,所以我试图通过手动执行此操作grunt.event.on('watch'