grunt连接退出而不是提供本地文件

时间:2015-03-08 23:12:48

标签: javascript node.js gruntjs server connect

我有一个以下Gruntfile.js,其中只包含两个任务:第一个解析/生成文件,第二个任务grunt-contrib-connect启动Web服务器:

module.exports = function(grunt) {

  grunt.initConfig({
    aglio: {
      docs: {
        files: {
          'index.html': 'api.md',
        },
        options: {
          theme: "slate"
        }
      }
    },
    connect: {
      server: {
        options: {
          port: 9001,
          hostname: 'localhost',
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-aglio');

  grunt.registerTask('default', ['aglio', 'connect']);
};

问题是服务器静默退出,我不知道为什么。在控制台中,它看起来像这样:

tducin@tducin-home:~/Workspace/duck-blueprint$ grunt
Running "aglio:docs" (aglio) task
>> Written to index.html

Running "connect:server" (connect) task
Started connect web server on http://localhost:9001

Done, without errors.

有人能指出我的connect任务配置有什么问题吗?

1 个答案:

答案 0 :(得分:3)

您是否阅读了grunt-contrib-connect的文档?

根据该文档。如果要在完成grunt任务后保持服务器的活动,则需要设置keepalive为真。

connect: {
  server: {
    options: {
      port: 9001,
      hostname: 'localhost',
      keepalive : true
    }
  }
  

让服务器无限期保持活力。请注意,如果启用此选项,则此任务后指定的任何任务将永远不会运行。默认情况下,一旦grunt的任务完成,Web服务器就会停止。此选项会更改该行为。

https://github.com/gruntjs/grunt-contrib-connect/blob/master/README.md