我在一个文件夹中有两个带有.jison扩展的文件。每次保存时,我都喜欢运行命令jison [the_file].jison。如何使用节点完成此操作?Nodemon和gulp似乎是一个有效的解决方案,但我对两者都没有经验,并且喜欢保持简单。
发布于 2015-12-17 09:37:27
喝了一口,这会很简单。关键是设置一个watch,它将在每次文件更改时触发一个任务:
像这样的事情应该会让你开始:
var exec = require('gulp-exec');
gulp.task('jison', function() {
return gulp.src(['**/*.jison'])
.pipe(exec('jison <%= file.path %>.jison'));
});
gulp.task('watch', function() {
gulp.watch(['**/*.jison'], ['jison']);
});
gulp.task('default', ['watch', 'jison']);因此,上面我们定义了一个名为jison的任务,观察.jison文件的任何变化,并设置default任务。引入gulp-exec来运行bash命令。
发布于 2016-01-20 20:36:30
如果您想使用咕噜,只需安装npm "grunt“"grunt-shell”"grunt-contrib-watch“,这是您的Gruntfile.js的示例
module.exports = function(grunt) {
// Define tasks
grunt.initConfig({
watch:{
scripts:{
files: ['<path-to>/<jison-file>.jison'],
tasks: ['shell:jison_compile'],
options: {
interrupt : true
}
}
},
shell: {
jison_compile:{
command: 'jison <path-to>/<jison-file>.jison'
}
},
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task(s).
grunt.registerTask('default', ['shell:jison_compile']);
};然后,您可以使用grunt来运行它的默认任务(编译jison文件),也可以使用grunt watch让它等待指定文件中的更改
https://stackoverflow.com/questions/34330846
复制相似问题