0

So, I've recently started using Grunt, and it's working! Great.

As I use LESS, I decided I want development and production version of the compiled CSS - so I decided to add in the relevant targets. However, I'm now getting the error specified in the title.

I've looked at StackOverflow, and a lot of the solutions are regarding the [] around the 'files' option(is that the right word?), which I lack. I don't know where in the file I need to add them, and I've tried some places and it doesn't work.

Adding [] to the 'src' option I have doesn't work either.

Here's the first part of my Gruntfile - I don't believe the rest is needed.

module.exports = function(grunt) {

grunt.initConfig({

   pkg: grunt.file.readJSON('package.json'),
   less: { 
    production: { 
        options: { 
            path: ["css"], 
            cleancss: true 
    }, 

     src: {
        expand: true,
        cwd:    "css/",
        src:    ['*.less', '!_*.less'],
        dest:   "production/css/", 
        ext:    ".css"
}   
 }, 

 dev: {
   options: { 
    path: ["css"] 
}, 

src: { 
        expand: true,
        cwd:    "css/",
        src:    ['*.less', '!_*.less'],
        dest:   "css/", 
        ext:    ".css"
}
   }

         }, 

Thanks! I'm sorry in advance if this question is a repeat, but nothing else gives me any hints.


Have you tried setting the files in the same way as the docs? This specifies the source files slightly differently to how you have it:

less: {
  development: {
    options: {
      paths: ["assets/css"]
    },
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  },
  production: {
    options: {
      paths: ["assets/css"],
      cleancss: true,
      modifyVars: {
        imgPath: '"http://mycdn.com/path/to/images"',
        bgColor: 'red'
      }
    },
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  }
}

See the usage examples in the docs for more clarification: https://github.com/gruntjs/grunt-contrib-less#usage-examples

4

1 回答 1

1

您是否尝试过以与文档相同的方式设置文件?这指定的源文件与您拥有它的方式略有不同:

less: {
  development: {
    options: {
      paths: ["assets/css"]
    },
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  },
  production: {
    options: {
      paths: ["assets/css"],
      cleancss: true,
      modifyVars: {
        imgPath: '"http://mycdn.com/path/to/images"',
        bgColor: 'red'
      }
    },
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  }
}

有关更多说明,请参阅文档中的用法示例:https ://github.com/gruntjs/grunt-contrib-less#usage-examples

于 2014-04-29T16:25:13.157 回答