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

标签 javascript node.js server gruntjs grunt-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 任务配置有什么问题吗?

最佳答案

您阅读过 grunt-contrib-connect 的文档吗?

根据文档。如果希望在 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

关于javascript - grunt connect 退出而不是提供本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28933018/

相关文章:

python - 使用 nohup (LINUX) 访问后台工作的进度 - 获取前台

javascript - GetImageData 未返回比较 2 个图像的预期结果

Javascript 没有获取属性值

javascript - 在对象上使用 .map() 从不同的父键获取值

node.js - Sequelize truncate 方法删除表

google-cloud-platform - 在 Google Cloud 中安装 Label Studio 并使其可通过公共(public) IP 使用

javascript - 实时更改 jQuery Tipsy 插件重力

javascript - 如何解释 Observable.of(Math.random()) 总是返回相同的值?

node.js - 通过 TS 使用路径映射调试 Nest App

Powershell Web 访问导致 404