Grunt在每个目录中编译所有.less到.css [英] Grunt compile all .less to .css in each directory

查看:138
本文介绍了Grunt在每个目录中编译所有.less到.css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我设置了我的网站来使用模块,其中每个模块都有它自己的.less文件,这些文件需要被编译到.css中。

文件夹结构:
/ common / modules / {module-name} /style.less



我需要将所有style.less文件转换为同一目录中的style.css文件。例如:

/common/modules/clock/style.less 需要被编译为 /common/modules/clock/style.css



我不想单独将每个模块添加到我的grunt文件,有没有办法做到这一点动态? 解决方案

http://gruntjs.com/configuring-tasks#globbing-patterns



您可以定义以下任务:

  grunt.initConfig({
less:{
compileCore :{
options:{
strictMath:true
},
files:[{
expand:true,
src:['/ common / modules /**/style.less'],
ext:'.css',
extDot:'first'
}]
}
}
});


So I have setup my site to use modules, in which each module has it's own .less file which needs to be compiled into .css.

Folder Structure: /common/modules/{module-name}/style.less

I need all the style.less files to be converted into style.css files in the same directory. For example:

/common/modules/clock/style.less would need to be compiled to /common/modules/clock/style.css

I don't want to have to add each of the modules individually to my grunt file, is there a way to do this dynamically?

解决方案

See also: http://gruntjs.com/configuring-tasks#globbing-patterns

You can define the following task:

  grunt.initConfig({
    less: {
      compileCore: {
        options: {
          strictMath: true
        },
        files: [{
          expand: true,
          src: ['/common/modules/**/style.less'], 
          ext: '.css',
          extDot: 'first'
        }]
      }
  }
  });

这篇关于Grunt在每个目录中编译所有.less到.css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆