使用 grunt 插件

Using grunt plugins

我有以下 gruntfile

module.exports = function (grunt) {



    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        htmlhint: {
            build: {
                options: {
                    'tag-pair': true,
                    'tagname-lowercase': true,
                    'attr-lowercase': true,
                    'attr-value-double-quotes': true,
                    'doctype-first': true,
                    'spec-char-escape': true,
                    'id-unique': true,
                    'head-script-disabled': true,
                    'style-disabled': true
                },
                src: ['index.html']
            }
        },
        watch: {
            html: {
                files: ['index.html'],
                tasks: ['htmlhint']
            }
        }
    });

    require("matchdep").filterDev("grunt-").forEach(grunt.loadNpmTasks);


    grunt.registerTask('default', ['watch']);



};

当我在 cmd 中尝试 运行 grunt 时,它给了我这个错误

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

Aborted due to warnings.

我该如何解决这个问题

尝试将 htmlhint 任务添加到默认值:

grunt.registerTask('default', ['htmlhint', 'watch']);

还要确保您已安装 grunt-htmlhint 并将其保存到您的 package.jsonmatchdep 在您正在使用的 filterDev 方法中使用它,因此如果未保存,则不会加载它。

npm install grunt-htmlhint --save-dev

或者您可以使用以下方式手动加载任务:

grunt.loadNpmTasks('grunt-htmlhint');