我在node.js中有一个Web应用程序,我想用nodemon启动,因此每次主脚本更改时,Web应用程序都可以重新启动。
同时,我有我的 CoffeeScript 文件,每次发生任何更改时我都需要重新编译。
我设置了一个 grunt-contrib-watch 任务来监听 app/frontend/*.coffee
文件,以调度咖啡解析器。
然而,这似乎并没有发生,因为 nodemon 任务也在监听。
我在nodemonignore中设置了app/frontend/
文件夹。
我还设置了nodemon并观察并发。
尽管如此,每次我编辑 CoffeeScript 时,咖啡任务都没有被执行。
这是我的 Gruntfile
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
concurrent: {
dev: [
'nodemon',
'watch'
],
options: {
logConcurrentOutput: true
}
},
coffee: {
compile: {
files: {
'app/public/app.js': ['app/frontend/*.coffee']
}
}
},
nodemon: {
dev: {
script: 'app/index.js',
options: {
ignore: ['app/frontend/**', 'app/public/**']
}
}
},
watch: {
scripts: {
files: 'app/frontend/*.coffee',
tasks: ['coffee'],
options: {
spawn: false
}
}
}
});
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-nodemon');
// Default task(s).
grunt.registerTask('default', ['coffee', 'nodemon', 'watch']);
};
最佳答案
您的 Gruntfile 指示 Grunt 作为默认任务按顺序运行 nodemon
和 watch
(因此 watch
永远不会运行,因为 nodemon
永远不会完成)。
您需要在最后一行显式包含并发
任务:
grunt.registerTask('default', ['coffee', 'concurrent']);
关于node.js - 如何让 grunt watch 和 grunt nodemon 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33557351/