grunt-express-server与contrib-watch [英] grunt-express-server with contrib-watch

查看:128
本文介绍了grunt-express-server与contrib-watch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图尽快使用 grunt-express-server grunt-contrib-watch 随着我的快递服务器启动,它似乎不再需要观看或重新加载。我有服务器设置在后台生成。
我的项目在这里: https://github.com/RyanHirsch/firem

I am trying to use both grunt-express-server and grunt-contrib-watch however, as soon as my express server starts, it no longer seems to do any watching or reloading. I have the server setup to spawn in the background. My project is here: https://github.com/RyanHirsch/firem

这是我的Gruntfile.js

Here is my Gruntfile.js

module.exports = function(grunt) {
  require('load-grunt-tasks')(grunt);
  // Project configuration.
  grunt.initConfig({
    watch: {
      options: {
        livereload: true,
      },
      express: {
        files:  [ 'index.html', 'server.js' ],
        tasks:  [ 'express:dev' ],
        options: {
          spawn: false
        }
      }
    },
    express: {
      options: {
        // Override defaults here
      },
      dev: {
        options: {
          script: 'server.js'
        }
      }
    }
  });

  grunt.registerTask('default', ['express:dev','watch']);
};


推荐答案

我能克隆你的项目,并且可以通过 server.js 中的以下调整来获取所有运行的内容:

I was able to clone your project and able to get everything running with the following tweak in server.js:

app.listen(3000);

into:

app.listen(3000, function() {
  console.log('Server listening on port 3000');
});

根据grunt-express-server的用法文档,您的服务器应该 console.log 一些输出,以便grunt任务可以告诉服务器已成功启动。

According to the grunt-express-server's "Usage" docs, your server should console.log some output so that the grunt task can tell that the server has started successfully.

(这是因为启动服务器是异步的,这可能会导致LiveReload的竞争条件)

(This is because starting the server is asynchronous, which can cause a race-condition with LiveReload)

否则,对于不希望其应用程序输出的纯粹主义者,有一个延迟选项:)

Otherwise, there is a delay option for purists who don't want any output from their application :)

这篇关于grunt-express-server与contrib-watch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆