简体   繁体   English

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

[英]Compliling multiple folder from LESS to CSS using grunt watch?

I am trying to compile Less files using grunt watch, i have 2 folders containing less files and 2 destination folders but it shows me an error: 我正在尝试使用grunt watch编译较少的文件,我有2个包含较少文件的文件夹和2个目标文件夹,但是它显示了一个错误:

object has no method 'indexOf; 对象没有方法'indexOf;

gruntfile.js code: gruntfile.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']);
};

As u can see ;files:' option is there which includes 2 different folders. 如您所见,“文件:”选项在那里包括2个不同的文件夹。

You could try creating 2 targets (dunno if that's the right term for that) and separate your concerns across them. 您可以尝试创建2个目标(如果这是正确的术语,请使用duno),然后将您的关注点分开。 Then run them for watch . 然后运行它们以进行watch Also tweaked your watch task to monitor the themes by using deep-monitor wildcard 还调整了监视任务,以使用深度监视器通配符监视themes

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

I think you should enclose this in "mode" variable, such as "development" or "production". 我认为您应该将其包含在“模式”变量中,例如“开发”或“生产”。 Like this: 像这样:

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'
      }]
    }
  }

Also, after the "files" array, there is an extra unnecessary comma, removed in my example... 另外,在“文件”数组之后,还有一个多余的逗号,在我的示例中已删除...

Update the watch to the following afterward: 之后将手表更新为以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM