0

我已经配置了 grunt-contrib-connect 但服务器没有保持活动状态:

包.json

{
  "name": "my-project-name",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-connect": "^0.9.0",
  }
}

Grundfilesnippet:

// Project configuration.
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    connect: {
        options: {
            port: 9000,
            base: 'src/main/webapp',
            keepalive: 'true'
        }
    }
});

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

grunt.registerTask('server', function () {
    grunt.task.run([
        'connect'
    ]);
});

运行任务“服务器”时,服务器启动和停止,忽略选项:

Running "server" task
Done, without errors.

但是更改配置如下:

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    connect: {
        abc:{
            options: {
                port: 9000,
                base: 'src/main/webapp',
                keepalive: 'true'
            }
        }
    }
});

使任务运行“connect:abc”并选择选项。为什么忽略任务默认选项?

Running "server" task
Running "connect:abc" (connect) task
Waiting forever...
Started connect web server on http://0.0.0.0:9000
4

1 回答 1

1

在您的第一个示例中,您的配置没有目标,在您的第二个示例中,它有一个目标“abc”。

添加一个目标应该可以工作,我认为目标甚至可以是空的!:

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    connect: {          
        options: {
            port: 9000,
            base: 'src/main/webapp',
            keepalive: true
        },
        abc: {}
    }
});
于 2014-11-22T21:30:12.333 回答