3

我有一个非常简单的 grunt 设置。唯一活跃的插件是 grunt-contrib-connect。这是我的 package.json 文件:

{
  "name": "gruntApp",
  "version": "0.1.0",
  "description": "An application for testing Grunt.js",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-connect": "~0.3.0"
  }
}

我的 gruntfile 看起来像这样:

module.exports = (grunt) ->
  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'
    log:
      start: 'Grunt is starting for application <%=pkg.name%> v<%=pkg.version%>'
      end: 'Grunt is finishing'
  grunt.registerMultiTask 'log', ->
    grunt.log.writeln this.data
  grunt.registerTask 'printConfig', ->
    grunt.log.writeln JSON.stringify grunt.config(), null, 2
  grunt.loadNpmTasks 'grunt-contrib-connect'
  grunt.registerTask 'default', [
    'log:start'
    'log:end'
  ]

我的自定义任务有效,但grunt connect没有。这是控制台的输出:

$ grunt connect -v

Initializing
Command-line options: --verbose

Reading "Gruntfile.coffee" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-connect" local Npm module tasks.
Reading /Users/eric/Projects/gruntApp/node_modules/grunt-contrib-connect/package.json...OK
Parsing /Users/eric/Projects/gruntApp/node_modules/grunt-contrib-connect/package.json...OK
Loading "connect.js" tasks...OK
+ connect
Loading "Gruntfile.coffee" tasks...OK
+ default, log, printConfig

Running tasks: connect

Running "connect" task
>> No "connect" targets found.
Warning: Task "connect" failed. Use --force to continue.

Aborted due to warnings.

那是怎么回事,哟?看起来它检测到了连接任务,但后来它找不到目标。我错过了什么?我按照这里的指示进行操作:https ://github.com/gruntjs/grunt-contrib-connect#getting-started

4

1 回答 1

5

配置任务 + 目标是使其从命令行可用的重要部分。要制作 grunt connect work,请将配置添加到.initConfig

grunt.initConfig
  connect:
    server:
      options:
        base: 'app'
        keepalive: true
于 2013-04-24T18:09:22.573 回答