Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用grunt watch将多个文件夹从LESS编译为CSS?_Javascript_Json_Gruntjs_Grunt Contrib Watch - Fatal编程技术网

Javascript 使用grunt watch将多个文件夹从LESS编译为CSS?

Javascript 使用grunt watch将多个文件夹从LESS编译为CSS?,javascript,json,gruntjs,grunt-contrib-watch,Javascript,Json,Gruntjs,Grunt Contrib Watch,我正在尝试使用grunt watch编译更少的文件,我有两个包含更少文件的文件夹和两个目标文件夹,但它显示了一个错误: 对象没有“indexOf”方法 GrunFile.js代码: module.exports = function(grunt) { grunt.initConfig({ less: { options: { paths: ["./less"], yuicompress: true }, files:

我正在尝试使用grunt watch编译更少的文件,我有两个包含更少文件的文件夹和两个目标文件夹,但它显示了一个错误:

对象没有“indexOf”方法

GrunFile.js代码:

module.exports = function(grunt) {
  grunt.initConfig({
    less: {
      options: {
        paths: ["./less"],
        yuicompress: true
      },
      files: [{
        expand: true,
        cwd: './less',
        src: ['*.less', '!{fonts, variable, mixins}*.less'],
        dest: './css',
        ext: '.css'
      }, {
        expand: true,
        cwd: './less',
        src: '*.less/themes',
        dest: './css/themes',
        ext: '.css'
      }],
    },
    watch: {
      files: "./less/*",
      tasks: ["less"]
    }
  });
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-watch');

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

正如你所看到的;文件:'选项包括两个不同的文件夹。

您可以尝试创建两个目标(不知道这是否是正确的术语),并将您的关注点分开。然后运行它们查看
。还通过使用深度监视器通配符调整了监视任务,以监视
主题

less : {
  options : {...},
  styles : {...},
  themes : {...},
},
watch : {
  files : './less/**/*.less',
  tasks : ['less:styles','less:themes'],
}

我认为您应该将其包含在“mode”变量中,例如“development”或“production”。 像这样:

less: {
   development: {
      options: {
        paths: ["./less"],
        yuicompress: true
      },
      files: [{
        expand: true,
        cwd: './less',
        src: ['*.less', '!{fonts, variable, mixins}*.less'],
        dest: './css',
        ext: '.css'
      }, {
        expand: true,
        cwd: './less',
        src: '*.less/themes',
        dest: './css/themes',
        ext: '.css'
      }]
    }
  }
另外,在“files”数组之后,还有一个多余的不必要的逗号,在我的示例中删除了

之后将手表更新为以下内容:

watch: {
      files: "./less/*",
      tasks: ["less:development"]
    }