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

前端 未结 3 1445
感情败类
感情败类 2020-12-29 10:00

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



        
相关标签:
3条回答
  • 2020-12-29 10:14

    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"
        }
    },
    
    0 讨论(0)
  • 2020-12-29 10:19

    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"
        }
    }
    
    0 讨论(0)
  • 2020-12-29 10:26

    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"

    0 讨论(0)
提交回复
热议问题