Grunt:警告:对象#<Object>没有方法'indexOf'使用--force继续

azz*_*z0r 2 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.
Run Code Online (Sandbox Code Playgroud)

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


};
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助,谢谢

Kyl*_*ung 6

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

files仅当您要为每个目标定义多个src/dest块时,才需要该属性.

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

less: {
  targetname: {
    expand: true,
    cwd: 'public/css',
    src: ['*.less'],
    dest: 'public/css',
    ext: '.css'
  },
  options: {
    compress: true,
    yuicompress: true,
    optimization: 2
  }
},
Run Code Online (Sandbox Code Playgroud)

该名称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
  }
},
Run Code Online (Sandbox Code Playgroud)