grunt-contrib-less not working (no errors but no output css)

2.9k views Asked by At

I have a less compile grunt task where relative path to less files from grunt installed folder is raw/less/source_map/

here is the grunt file.

Gruntfile: (EDIT: changed to @Yogesh Khatri's code still same issue)

module.exports = function(grunt) {
    grunt.initConfig({
        less: {
            files: { "raw/less/source_map/style.css" : "raw/less/source_map/style.less" }
        },
        watch: {
            js: {
                files: ['raw/less/source_map/style.less'],
                    tasks: ['default'],
                }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', ['less']);
};

on running it the command line displays

^CMacPro:grunt sagiavinashvarma$ grunt watch
Running "watch" task
Waiting...
>> File "raw/less/source_map/style.less" changed.
Running "less:files" (less) task

Done, without errors.
Completed in 1.862s at Tue Dec 09 2014 15:03:37 GMT+0530 (IST) - Waiting...

but there is no style.css output. I have written the simplest grunt task without any options. can anyone point out whats wrong with this.

1

There are 1 answers

1
Yogesh Khatri On

Edit: I got the problem. It isn't working because less task need a specific target to work.
Try to change the code like this

module.exports = function(grunt) {
    grunt.initConfig({
        less: {
          development: {
            files: { "raw/less/source_map/style.css" : "raw/less/source_map/style.less" }
          }
        },
        watch: {
            js: {
                files: ['raw/less/source_map/style.less'],
                    tasks: ['default'],
                }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', ['less']);
};

I got the error by running grunt --verbose which shows lot more information about the tasks. It gave me the output like

Verifying property less.files exists in config...OK
File: [no files]
Options: report="min", banner=""
>> Destination not written because no source files were provided.

of which searching led me to this :- grunt-contrib-less cannot find source files even though path is correct