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

grunt connect exits instead of serving local files

我有一个后续 Gruntfile.js,它只包括两个任务:第一个 parses/generates 文件和第二个 grunt-contrib-connect,启动网络服务器:

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 任务配置有什么问题吗?

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

根据 document.You 如果想在 grunt 任务完成后保持服务器活动,需要设置 keepalive true。

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

Keep the server alive indefinitely. Note that if this option is enabled, any tasks specified after this task will never run. By default, once grunt's tasks have completed, the web server stops. This option changes that behavior.

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