少任务未找到错误

Less task not found error

我最近开始使用 grunt,但似乎无法正常工作:我使用 npm 安装了 grunt-cli,还使用 ​​npm 安装了一些 grunt 模块,没有出现任何问题。我正在尝试将所有 bootstrap 框架的 less 文件编译成一个 css 文件,但一直收到错误消息,提示未找到 less 任务。我确信一切都在它应该在的地方并且我在 gruntfile 中加载了 grunt-contrib-less 插件。知道我可能哪里出错了吗?

我的package.json的内容:

{
    "name": "dConference",
    "version": "0.1.0",
    "devDependencies": {
    "grunt": "latest",
    "grunt-contrib-jshint": "latest",
    "jshint-stylish": "latest",
    "grunt-contrib-uglify": "latest",
    "grunt-contrib-less": "latest",
    "grunt-contrib-cssmin": "latest",
    "grunt-contrib-watch": "latest" 
    }
}

还有我的gruntfile.js的内容:

//gruntfile specifying all tasks to be performed

module.exports = function(grunt){
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        //all configuration goes here
        less: {
            build: {
                files: [{
                    expand: true,
                    cwd: "components/less",
                    src: ["*.less"]
                    dest: "css/main.css"
                }               ]
            }
        }

    });

    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks("grunt-contrib-cssmin");
    grunt.loadNpmTasks("grunt-contrib-watch");



};

我做了Gruntfile.js如下。

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        less: {
            build: {
                files: {
                    'css/main.css': 'components/less/bootstrap.less'
                }
            }
        }

    });

    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks("grunt-contrib-cssmin");
    grunt.loadNpmTasks("grunt-contrib-watch");
};

并且 运行 "grunt less" 在项目根文件夹上成功。 "grunt less"命令成功运行后,在css文件夹下生成main.css

项目结构为:

grunt-test-project

  • components/less
    • mixins 文件夹
    • 所有其他 bootstrap 少文件
  • css
  • Gruntfile.js
  • package.json

请在你这边试试,告诉我结果。