0

我创建了一个新节点项目,我安装了很多模块并创建了第一个 index.js 文件

包.json

{
  "name": "parser-test",
  "version": "1.0.0",
  "description": "parser test",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "luca bottoni",
  "license": "ISC",
  "dependencies": {
    "node-cmd": "^3.0.0"
  },
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-contrib-jshint": "^1.1.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-exec": "^3.0.0"
  }
}

index.js(失败了,因为我想看到 jshint 消息!)

console.log("test");
a={a=6};

如果我从我看到的项目文件夹中发送 cmd jshint index.js(工作正常):

index.js: line 3, col 5, Expected ':' and instead saw '='.
1 error

现在我想使用 grunt 任务来检查我的文件

Gruntfile.js

module.exports = function(grunt) {
    // Project configuration.
    grunt.initConfig({
                     pkg:  grunt.file.readJSON('package.json'),
                     watch:{
                         scripts:{
                             files:["./*.js"],
                             tasks:['jshint']
                         }
                     },
                     jshint: {
                         files: ['Gruntfile.js',"index.js"]
                     }
                 });
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task(s).
grunt.registerTask('default', ['watch:scripts']);
grunt.registerTask('jshint', ['jshint']);
};

现在我尝试使用带有命令 grunt jshint 的单任务 jshint,但没有看到任何消息。如果我使用手表,则仅在第一次和之后不检查文件 index.js 上的任何更改后观看任务。

我不明白为什么直接命令 jshint 工作,但任务 grunt 保持冻结

4

1 回答 1

0

经过多次测试我已经解决了

我有关于 grunt 命令的详细信息

grunt jshint --verbose我看到了无限:

运行“jshint”任务

运行“jshint”任务

运行“jshint”任务

运行“jshint”任务

运行“jshint”任务

运行“jshint”任务

定义中的注册任务和任务具有相同的名称“jshint”,我在 grunt.registerTask(' jshints ', ['jshint']);中修改了名称

现在工作正常

于 2017-09-13T15:30:45.123 回答