Grunt gruntfile.js和grunt手表

时间:2013-11-07 14:27:25

标签: gruntjs grunt-contrib-watch grunt-contrib-compass

**我希望能够使用指南针,但Grunt手表不起作用,并给我一些奇怪的错误:**

Running "watch" task
Waiting...Verifying property watch exists in config...ERROR
>> Unable to process task.
Warning: Required config property "watch" missing.

/Applications/MAMP/htdocs/davide77.bitbucket.org/sky-route-1/node_modules/grunt-contrib-compass/node_modules/tmp/lib/tmp.js:261
  throw err;
        ^
RangeError: Maximum call stack size exceeded
module.exports = function (grunt) {

  // Project configuration.
  grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),

    compass: {

      dev: {
        src: 'sass',
        dest: 'stylesheets',
        outputstyle: 'expanded',
        linecomments: true,
        forcecompile: true,
        require: [
          'animate-sass',
          'mylib'
        ],
        debugsass: true,
        images: '/assets/images',
        relativeassets: true
      },
      prod: {
        src: 'sass',
        dest: 'stylesheets',
        outputstyle: 'compressed',
        linecomments: false,
        forcecompile: true,
        require: [
          'animate-sass',
          'mylib'
        ],
        debugsass: false,
        images: '/assets/images',
        relativeassets: true
      },
      dist: {
        src: 'sass',
        dest: 'stylesheets',
        outputstyle: 'compressed',
        linecomments: false,
        forcecompile: true,
        require: [
          'animate-sass',
          'mylib'
        ],
        debugsass: false,
        images: '/assets/images',
        relativeassets: true
      },

      watch: { // for development run 'grunt watch'
        compass: {
          files: ['sass/*.scss'],
          tasks: ['compass:dev']
        }
      }
    }
  });

  // Default task(s). 

  //grunt.registerTask('default', 'compass:dev');

  grunt.registerTask('watch', ['watch']);
  grunt.loadTasks('watch');

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-compass');
  grunt.registerTask('default', ['compass']);
};

2 个答案:

答案 0 :(得分:1)

我已经重新格式化了您的代码,您现在应该看到您已将手表配置放在罗盘配置对象中,这是不正确的。

另外,为什么要包含此代码:?

grunt.registerTask('watch', ['watch']);
grunt.loadTasks('watch');

可能这也可能导致一些问题,我建议删除它。

答案 1 :(得分:0)

我想这一节:

grunt.registerTask('watch', ['watch']);
grunt.loadTasks('watch');

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.registerTask('default', ['compass']);

应如下所示:

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');

grunt.registerTask('watch', ['watch']);
grunt.registerTask('default', ['compass']);