最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why doesn't grunt-contrib-connect find the connect task? - Stack Overflow

programmeradmin1浏览0评论

I have a very simple grunt setup. The only active plugin is grunt-contrib-connect. Here is my package.json file:

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

My gruntfile looks like this:

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'
  ]

My custom tasks work, but grunt connect does not. Here is the output at the console:

$ 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.

What up with that, yo? It looks like it detects the connect task, but later it can't find the target. What am I missing? I was following the directions from here:

I have a very simple grunt setup. The only active plugin is grunt-contrib-connect. Here is my package.json file:

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

My gruntfile looks like this:

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'
  ]

My custom tasks work, but grunt connect does not. Here is the output at the console:

$ 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.

What up with that, yo? It looks like it detects the connect task, but later it can't find the target. What am I missing? I was following the directions from here: https://github./gruntjs/grunt-contrib-connect#getting-started

Share Improve this question edited Dec 24, 2013 at 22:41 SimplGy asked Apr 24, 2013 at 16:56 SimplGySimplGy 20.4k15 gold badges111 silver badges150 bronze badges 2
  • The only targets I see are pkg and log. There is no connect target. Have a look at github./gruntjs/grunt-contrib-connect#usage-examples. – Felix Kling Commented Apr 24, 2013 at 17:05
  • I thought that using grunt.loadNpmTasks 'grunt-contrib-connect' would load the targets and tasks from that module. Not so, I see that adding the target connect to initConfig solves the issue. – SimplGy Commented Apr 24, 2013 at 17:09
Add a ment  | 

1 Answer 1

Reset to default 5

Configuring the task + target is an important part of making it available from the mand line. To make grunt connect work, add configuration to .initConfig:

grunt.initConfig
  connect:
    server:
      options:
        base: 'app'
        keepalive: true
发布评论

评论列表(0)

  1. 暂无评论