javascript - Gruntfile.js - 未找到任务 “default”

标签 javascript node.js gruntjs

我正在尝试扩展此处构建的 D3 Calendar Viz 库:https://github.com/kamisama/cal-heatmap

我已经克隆了该存储库。该代码使用 Grunt 作为构建过程,因此我安装了 Grunt-Cli 并在目录中运行 npm install ,效果很好。运行 grunt 我收到错误:

Warning: Task "default" not found. Use --force to continue.

我已将 grunt.js 文件放入 http://esprima.org/demo/validate.html并且它已返回并且没有错误。我不明白为什么 grunt 不在这里工作。

这是 grunt.js 文件:

module.exports = function(grunt) {

    "use strict";

    var headerComment = "/*! <%= pkg.name %> v<%= pkg.version %> (<%= grunt.template.today() %>)\n" +
                " *  ---------------------------------------------\n" +
                " *  <%= pkg.description %>\n" +
                " *  <%= pkg.homepage %>\n" +

                " *  Licensed under the <%= pkg.license %> license\n" +
                " *  Copyright 2014 <%= pkg.author.name %>\n" +
                " */\n";

    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        jshint: {
            options: {
                jshintrc: ".jshintrc"
            },
            lib: {
                src: ["src/<%= pkg.name %>.js"]
            },
            test: {
                options: {
                    jshintrc: "test/.jshintrc"
                },
                src: ["test/test.js", "test/test-amd.js"]
            }
        },
        csslint: {
            base: {
                src: "<%= pkg.name %>.css",
                rules: {
                    "known-properties": false,
                    "box-sizing": false
                }
            }
        },
        uglify: {
            options: {
                banner: headerComment
            },
            base: {
                files: {
                    "<%= pkg.name %>.min.js" : ["<%= pkg.name %>.js"]
                }
            }
        },
        qunit: {
            options: {
                "--web-security": "no",
                coverage: {
                    src: ["src/*.js"],
                    instrumentedFiles: "temp/",
                    htmlReport: "report/coverage",
                    coberturaReport: "report/"
                }
            },
            all: ["test/*.html"]
        },
        concat: {
            options: {
                banner: headerComment + "\n"
            },
            js: {
                src: ["src/<%= pkg.name %>.js"],
                dest: "<%= pkg.name %>.js"
            },
            test: {
                src: ["test/src/function.js", "test/src/**/*.js"],
                dest: "test/test.js"
            }
        },
        coveralls: {
            options: {
                coverage_dir: "coverage/"
            }
        },
        watch: {
            scripts: {
                files: "test/src/**/*.js",
                tasks: ["concat:test"],
                options: {
                    interrupt: true,
                }
            },
            lint: {
                files: "src/*.js",
                tasks: ["jshint:lib"],
                options: {
                    interrupt: true,
                }
            }
        }
    });

    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-css");
    grunt.loadNpmTasks("grunt-contrib-qunit");
    grunt.loadNpmTasks("grunt-contrib-concat");
    grunt.loadNpmTasks("grunt-karma-coveralls");
    grunt.loadNpmTasks("grunt-contrib-watch");

    // TO RUN BEFORE COMMIT
    // ====================
    grunt.registerTask("quick-build", ["csslint", "jshint"]);

    // Full build without version bump
    grunt.registerTask("build", ["concat", "qunit", "csslint", "jshint", "uglify"]);

    // FOR TRAVIS
    // ==========
    grunt.registerTask("travis", ["jshint", "csslint"]);
};

这是 package.json 文件:

{
  "name": "cal-heatmap",
  "version": "3.5.2",
  "description": "Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data",
  "keywords": [
    "calendar",
    "graph",
    "d3js",
    "heat map"
  ],
  "main": "cal-heatmap.min.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "d3": ">= v3.0.6"
  },
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-uglify": "~0.7.0",
    "grunt-contrib-copy": "~0.7.0",
    "grunt-contrib-jshint": "~0.11.0",
    "grunt-contrib-concat": "~0.5.0",
    "grunt-contrib-watch": "~0.6.1",
    "grunt-contrib-qunit": "~0.5.2",

    "grunt-css": "~0.5.4",
    "grunt-replace": "~0.8.0",

    "phantomjs": "~1.9.15",
    "karma": "~0.12.31",
    "karma-coverage": "~0.2.7",
    "karma-qunit": "~0.1.4",
    "karma-phantomjs-launcher": "~0.1.4",
    "grunt-karma-coveralls": "~2.5.3",

    "qunitjs": "~1.17.0",
    "jquery": "~1.9.1"
  },
  "scripts": {
    "test": "grunt travis --verbose; ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/kamisama/cal-heatmap.git"
  },
  "homepage": "https://github.com/kamisama/cal-heatmap",
  "author": {
    "name": "Wan Qi Chen",
    "url": "http://www.kamisama.me"
  },
  "license": "MIT",
  "gitHead": "e7bf798c210e0c25df9f6857bdb268001ef67fd1",
  "volo": {
    "dependencies": {
      "d3": "d3"
    }
  },
  "jam": {
    "dependencies": {
      "d3": ">=3.0.6"
    }
  },
  "bugs": "https://github.com/kamisama/cal-heatmap/issues",
  "github": "https://github.com/kamisama/cal-heatmap",
  "categories": [
    "Data",
    "Visualization"
  ]
}

最佳答案

您需要定义默认任务,例如下面的。

grunt.registerTask("default", [ "lint", "test", "coverage" ]);

关于javascript - Gruntfile.js - 未找到任务 “default”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29148082/

相关文章:

javascript - Express.js (MYSQL) 中的 DELETE 函数不删除行

javascript - 对于本地模块,Grunt 失败并显示 "Cannot find module"

javascript - Karma 公共(public) api 缺少 configFile 选项

javascript - JS 中的 Scanf 和 Printf

javascript - 如何在启动时使用异步存储数据渲染 React Native 组件?

javascript - 管理 Node.js 中的运行时错误

javascript - 使用 Express REST API 编辑帖子

node.js - 从 grunt 中更新 NPM 模块

javascript - jquery不同的图像平滑悬停在所有浏览器上的背景

javascript - 从 JSON 配置文件加载到 HTML 文件中?