【问题标题】:How to make grunt watch and grunt nodemon work together如何让 grunt watch 和 grunt nodemon 一起工作
【发布时间】:2016-02-07 01:01:38
【问题描述】:

我在 node.js 中有一个 web 应用程序,我想用 nodemon 启动,所以每次主脚本更改时,webapp 都可以重新启动。 同时,我有我的咖啡脚本文件,每次更改时我都需要重新编译它们。 我已经设置了一个 grunt-contrib-watch 任务来监听app/frontend/*.coffee 文件,以调度咖啡解析器。 然而,这似乎并没有发生,因为 nodemon 任务也在监听。 我在 nodemon ignore 中设置了app/frontend/ 文件夹。 我还设置了 nodemon 并监视为并发。 尽管如此,每次我编辑咖啡脚本时,咖啡任务都没有被执行。

这是我的 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']);

};

【问题讨论】:

    标签: node.js gruntjs grunt-contrib-watch


    【解决方案1】:

    您的 Gruntfile 指示 Grunt 依次运行 nodemonwatch 作为默认任务(因此 watch 永远不会像 nodemon 一样运行)。

    您需要在最后一行明确包含concurrent 任务:

    grunt.registerTask('default', ['coffee', 'concurrent']);
    

    【讨论】:

      猜你喜欢
      • 2014-09-24
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-24
      • 2016-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多