【问题标题】:Using grunt plugins使用 grunt 插件
【发布时间】:2015-12-08 23:34:59
【问题描述】:

我有以下 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 时,它给了我这个错误

警告:未找到“默认”任务。使用 --force 继续。

由于警告而中止。

我该如何解决这个问题

【问题讨论】:

    标签: node.js gruntjs npm workflow


    【解决方案1】:

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

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

    还要确保您已安装 grunt-htmlhint 并将其保存到您的 package.jsonmatchdep 在你使用的 filterDev 方法中使用它,所以如果它没有保存,它就不会被加载。

    npm install grunt-htmlhint --save-dev
    

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

    grunt.loadNpmTasks('grunt-htmlhint');
    

    【讨论】:

    • 谢谢罗比。它显示警告为Warning: Task "htmlhint" not found. Use --force to continue. Aborted due to warnings.
    • 也许您还缺少grunt.loadNpmTasks('grunt-htmlhint');? - 虽然我猜forEach 应该涵盖这一点
    • 你跑npm install grunt-htmlhint --save-dev了吗?
    • 我正在使用 matchdep 通过运行导致问题的 require("matchdep").filterDev("grunt-").forEach(grunt.loadNpmTasks);' 来包含依赖项列表。我不知道原因 :( 。但是哇...我将依赖项单独包含为 grunt.loadNpmTasks ('grunt-htmlhint'); grunt.loadNpmTasks('grunt-contrib-watch'); 成功了。谢谢
    • 不用担心,当你使用 npm 安装 grunt 任务时,请确保使用 --save-dev,否则你的 matchdep.filterDev 将找不到模块
    猜你喜欢
    • 1970-01-01
    • 2015-04-05
    • 2023-03-11
    • 2016-06-15
    • 2012-11-04
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 2016-09-04
    相关资源
    最近更新 更多