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

 mobiledu2502852915 发布于 2023-01-12 10:18

错误

Running "less" task

Running "less:files" (less) task
Verifying property less.files exists in config...OK
Warning: 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 个回答
  • 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
      }
    },
    

    该名称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
      }
    },
    

    2023-01-12 10:21 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有