I'm using Grunt for building my web project. I installed grunt-contrib-less
package und added a task to my grunt.initConfig({..});
我正在使用Grunt来构建我的Web项目。我安装了grunt-contrib-less软件包,并在我的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.
当我通过较少的grunt运行目标时,它运行没有错误,但不会将较少的文件编译为css文件。
Running "less:files" (less) task
Done, without errors.
I have installed the lessc package via node, too. Doing lessc <source> <dest>
works fine.
我也通过节点安装了lessc包。执行lessc
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.
后来我想扫描整个js目录并编译所有新修改的* .less文件。
I have installed following versions:
我安装了以下版本:
grunt-cli v0.1.6
grunt v0.4.0
node v0.8.7
npm 1.1.49
BR, mybecks
BR,mybecks
3 个解决方案
#1
45
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)
glob模式js / base / * .css与任何文件都不匹配,因此没有目标。通常,这样的任务期望多个输入组合成单个输出。另外,请记住,较少的是多任务,而将文件作为较少的子项放置并不是您所期望的。 (它将它视为目标,而不是src / dest地图)
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?)
如果您希望将.less转换为.css,则可以使用动态扩展。 (或者您可以手动定义每个src / dest对,但是谁想要这样做?)
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"
}
}
#2
9
I used Anthonies solution but stil had an error
我使用过Anthonies解决方案,但stil有错误
Warning: Object true has no method indexOf
If I changed the order putting expand true
as second it gave me the error
如果我改变了订单,将expand扩展为true,那么它就给了我错误
Unable to read "less" file
where "less" was the value of the first item in my list.
其中“less”是我列表中第一项的值。
I solved it by changing files into an array like this:
我通过将文件更改为如下数组来解决它:
less: {
options: {
paths: ["js/base"]
},
files: [{
expand: true,
cwd: "js/base",
src: ["**/*.less"],
dest: "js/base",
ext: ".css"
}]
},
I used "grunt-contrib-less" : "^0.11.0"
我使用了“grunt-contrib-less”:“^ 0.11.0”
#3
6
This works for me, but modified to reflect this scenario:
这对我有用,但经过修改以反映这种情况:
less: {
options: {
paths: ["js/base"]
},
files: {
expand: true,
cwd: "js/base",
src: ["**/*.less"],
dest: "js/base",
ext: ".css"
}
},
#1
45
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)
glob模式js / base / * .css与任何文件都不匹配,因此没有目标。通常,这样的任务期望多个输入组合成单个输出。另外,请记住,较少的是多任务,而将文件作为较少的子项放置并不是您所期望的。 (它将它视为目标,而不是src / dest地图)
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?)
如果您希望将.less转换为.css,则可以使用动态扩展。 (或者您可以手动定义每个src / dest对,但是谁想要这样做?)
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"
}
}
#2
9
I used Anthonies solution but stil had an error
我使用过Anthonies解决方案,但stil有错误
Warning: Object true has no method indexOf
If I changed the order putting expand true
as second it gave me the error
如果我改变了订单,将expand扩展为true,那么它就给了我错误
Unable to read "less" file
where "less" was the value of the first item in my list.
其中“less”是我列表中第一项的值。
I solved it by changing files into an array like this:
我通过将文件更改为如下数组来解决它:
less: {
options: {
paths: ["js/base"]
},
files: [{
expand: true,
cwd: "js/base",
src: ["**/*.less"],
dest: "js/base",
ext: ".css"
}]
},
I used "grunt-contrib-less" : "^0.11.0"
我使用了“grunt-contrib-less”:“^ 0.11.0”
#3
6
This works for me, but modified to reflect this scenario:
这对我有用,但经过修改以反映这种情况:
less: {
options: {
paths: ["js/base"]
},
files: {
expand: true,
cwd: "js/base",
src: ["**/*.less"],
dest: "js/base",
ext: ".css"
}
},