使用grunt插件
我有以下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继续。
由于警告而中止。
我该如何解决
尝试将htmlhint
任务添加到默认值:
grunt.registerTask('default', ['htmlhint', 'watch']);
还要确保你已经安装了grunt-htmlhint
并将其保存到你的package.json
。 matchdep
在你使用的filterDev
方法中使用它,所以如果没有保存,它将不会被加载。
npm install grunt-htmlhint --save-dev
或者你可以使用下面的方法手动加载任务
grunt.loadNpmTasks('grunt-htmlhint');