Compile less files with grunt-contrib-less won't work

会有一股神秘感。 提交于 2019-11-30 05:12:00

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"
    }
}

I used Anthonies solution but stil had an error

Warning: Object true has no method indexOf

If I changed the order putting expand true as second it gave me the error

Unable to read "less" file

where "less" was the value of the first item in my list.

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"

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"
    }
},
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!