使用 Grunt 命令行覆盖 JSHint 选项

Override JSHint Options by using the Grunt Command-Line

通过调用

grunt jshint:path_to_file

我想覆盖默认的 JSHint 配置

grunt.initConfig({
  jshint: {
            options: {
              curly: true,
              eqeqeq: true,
              eqnull: true,
              browser: true,
              globals: {
                jQuery: true
              }
            },
            all: ['Gruntfile.js', 'Scripts/src/**/*.js']
        }

});

并且只包含该特定文件。 "grunt jshint path_to_file" 也可以,但我不想使用

grunt jshint --file=filePath

grunt.option 功能,除非它能满足我的需要。

这是否可以通过某种方式实现?

g运行t 的精神更多的是编码在 g运行t 文件中使用哪些文件,而不是在命令行上指定它。 所以我们需要更多关于你为什么要这样做的细节。我想象了 2 种可能性:

  • 您只想处理一个子组件:在这种情况下,您将为每个子组件声明不同的目标并从命令行调用这些目标:grunt jshint component1 在您的 G运行t文件:

    jshint: {
      component1: [filePath1],
      component2: [filePath2]
    }
    
  • 这是一个性能问题:您只想 jshint 一些文件,因为只有它们发生了变化。在这种情况下,结合 grunt-contrib-watch(在文件更改时 运行 jshint)和 grunt-newer(在修改后的文件上仅 运行)