Grunt Watch和Connect没有合作

时间:2015-02-13 00:43:26

标签: javascript gruntjs grunt-contrib-watch taskmanager grunt-contrib-connect

我正在尝试注册一个结合了grunt上的connect和watch任务的自定义任务,但它似乎只是在函数grunt.registerTask上运行数组的第一个元素(任务)。在这种情况下,它只是运行watch命令,而不是连接。

'use strict';

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    connect: {
      server: {
        options: {
          port: '8000',
          protocol: 'http',
          hostname: 'localhost',
          base: 'app',
          keepalive: true,
          livereload: true,
          open: true
        }
      }
    },
    wiredep: {
      task: {
        src: ['app/index.html'],
      }
    },
    jshint: {
      options: {
        reporter: require('jshint-stylish'),
        jshintrc: '.jshintrc'
      },
      all: [
        'GruntFile.js',
        'app/scripts/*',
        'test/spec/*'
      ]
    },
    sass: {
      dist: {
        files: {
          'app/stylesheets/main.css': 'app/sass/main.sass'
        },
        options: {
          compass: true
        }
      }
    },
    watch: {
      options: {
        livereload: true
      },
      styles: {
        files: ['app/sass/*.sass'],
        tasks: ['sass'],
        options: {
          livereload: true
        }
      },
      scripts: {
        files: ['app/scripts/*.js', 'GruntFile.js'],
        tasks: ['jshint'],
        options: {
          livereload: true
        }
      },
      bower: {
        files: ['bower.json'],
        tasks: ['wiredep']
      }
    }
  });
// ========================================================

// Loading npm tasks
// ========================================================
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-wiredep');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
// ========================================================

// Register npm tasks
// ========================================================
  grunt.registerTask('default', ['connect', 'wiredep', 'jshint', 'sass', 'watch']);
  grunt.registerTask('serve',['watch', 'connect:server']);
// ======================================================== 

};

如何将这两个任务与registerTask函数一起工作?

0 个答案:

没有答案