使用grunt-contrib-less编译更少的文件将无法工作 [英] Compile less files with grunt-contrib-less won't work

查看:148
本文介绍了使用grunt-contrib-less编译更少的文件将无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Grunt来构建我的Web项目。我安装了 grunt-contrib-less package和向我的 grunt.initConfig({..})添加了一个任务;

  less:{
options:{
paths:['js / base']
},
文件:{
'js / base / *。css':'js / base / *。less'
}
}
grunt less less 时,c $ c>

>,它运行没有错误,但不会将较少的文件编译为一个css文件。

 运行less:files(少)任务

完成,没有错误。

我也通过节点安装了 lessc 包。做 lessc< source> < dest> 可以正常工作。



目前,我已将 files选项直接指向一个目录,其中包含少一个测试文件。即使我将整个文件名写入 files选项,它也不会发生任何事情......



稍后,我想扫描整个js目录并编译所有新的已修改* .less文件。



我已经安装了以下版本:

  grunt-cli v0.1.6 
grunt v0.4.0
node v0.8.7
npm 1.1.49


mybecks

解决方案

glob模式 js / base / *。css 与任何文件都不匹配,因此没有目的地。通常,像这样的任务需要将多个输入合并为一个输出。另外,请记住 less 多任务,并将 files 作为一个小于的孩子没有达到你期望的水平。 (它将它视为目标,而不是src / dest映射)



如果要将.less转换为.less,可以使用< href =http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically =noreferrer>动态扩展。 (或者您可以手动定义每个src / dest对,但是谁愿意这么做?)

在您的情况下:

  less:{
options:{
paths:['js / base']
},
//目标名称
src:{
//不需要文件,下面的配置应该可以工作
expand:true,
cwd:js / base,
src: * .less,
ext:.css
}
}


I'm using Grunt for building my web project. I installed grunt-contrib-less package und added a task to my grunt.initConfig({..});

less : {
            options: {
                paths: ['js/base']
            },
            files: {
                'js/base/*.css' : 'js/base/*.less'
            }
        }

when I run the target less via grunt less, it runs without errors but doesn't compile the less file to a css file.

Running "less:files" (less) task

Done, without errors.

I have installed the lessc package via node, too. Doing lessc <source> <dest> works fine.

Currently I have pointed with the files option directly to one dir which contains one less file for testing. Even if I write the whole file name into files option, it happens nothing...

Later on I want to scan the whole js directory and compile all new modified *.less files.

I have installed following versions:

grunt-cli v0.1.6
grunt v0.4.0
node v0.8.7
npm 1.1.49

BR, mybecks

解决方案

The glob pattern js/base/*.css does not match any files, therefore there is no destination. Usually, tasks like this expect multiple inputs to combine into a single output. Also, bear in mind that less is a multi-task, and putting files as a child of less is not doing what you expect. (it is treating it as a target, not a src/dest map)

If you want a 1-1 transform of .less into .css, you can use dynamic expansion. (or you can define each src/dest pair manually, but who wants to do that?)

In your case:

less: {
    options: {
        paths: ['js/base']
    },
    // target name
    src: {
        // no need for files, the config below should work
        expand: true,
        cwd:    "js/base",
        src:    "*.less",
        ext:    ".css"
    }
}

这篇关于使用grunt-contrib-less编译更少的文件将无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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