Grunt:警告:对象#<object>没有方法&#39; indexOf&#39;使用--force继续</object>

时间:2014-06-02 14:06:16

标签: gruntjs

错误

Running "less" task

Running "less:files" (less) task
Verifying property less.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf' Use --force to continue.

Gruntfile.js

module.exports = function (grunt) {
  grunt.initConfig({


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


    less: {
      files: [
        {
          expand: true,
          cwd: 'public/css',
          src: ['*.less'],
          dest: 'public/css',
          ext: '.css'
        }
      ],
      options: {
        compress: true,
        yuicompress: true,
        optimization: 2
      }
    },


    watch: {
      files: "public/css/*",
      tasks: ["less"]
    },


  });

  grunt.loadNpmTasks("grunt-contrib-watch");
  grunt.loadNpmTasks("grunt-contrib-less");
  grunt.loadNpmTasks("grunt-contrib-requirejs");
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');




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


};

非常感谢任何帮助,谢谢

1 个答案:

答案 0 :(得分:6)

files被解释为上述配置中的目标。因为它位于任务级别而不是目标级别。

只有在您为每个目标定义多个src / dest块时才需要files属性。

由于您只有一个src / dest块,因此请修改配置以仅使用目标:

less: {
  targetname: {
    expand: true,
    cwd: 'public/css',
    src: ['*.less'],
    dest: 'public/css',
    ext: '.css'
  },
  options: {
    compress: true,
    yuicompress: true,
    optimization: 2
  }
},

名称targetname是任意的,可以命名为任何名称。


需要files的示例是以下多个src / dest块配置:

less: {
  targetname: {
    files: [
      { src: ['*.less'], dest: 'public/css/' },
      { src: ['other/*.less'], dest: 'other/css/' },
    ]
  },
  options: {
    compress: true,
    yuicompress: true,
    optimization: 2
  }
},