我有一个Grunt.js文件,它使用了“grunt-contrib watch”和"grunt-exec",原因是我想以一种独特的方式使用handlebars预编译器的一些自定义功能。
代码:
module.exports = function(grunt) {
grunt.initConfig({
watch: {
src: {
files: ['**/*.hbs']
}
},
exec: {
preCompileTemplate: {
cmd: function(inputFile) {
grunt.log.writeln('DERP DERP' + inputFile);
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
grunt.event.on('watch', function(action, filepath, target) {
grunt.task.run('exec:preCompileTemplate:' + filepath);
grunt.log.writeln('-------> ' + filepath);
grunt.log.writeln('-------> ' + target);
});
}我在运行grunt watch然后更改.hbs文件时遇到的问题是,带有------>的2个grunt.log.writeln如预期的那样回显到控制台。
问题是grunt.task.run似乎从来没有运行过,因为其中包含DERP DERP DERP的控制台日志从未出现过。
我不能在grunt-contrib watcher中运行任务吗?我是不是做错了?
发布于 2015-08-31 03:24:14
您需要在grunt.initConfig中配置任务。你可以在他们的官方网站上看到more。
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint', 'yourAwasomeTask']
}});https://stackoverflow.com/questions/24254880
复制相似问题