【问题标题】:Can I have multiple jsHint task configured in a single Grunt file?我可以在一个 Grunt 文件中配置多个 jsHint 任务吗?
【发布时间】:2013-05-13 16:25:39
【问题描述】:

我为 2 个不同的模块配置了一个 grunt 文件。在一项任务中,我可以提供多个来源,并且一切正常。 现在我的要求是为这两个模块提供不同的选项,比如说——我希望两个模块都有不同的 JsHint 规则,并且我希望这两个项目都有单独的缩小文件和一个通用的缩小文件。

Gruntfile.js ->

jshint: {

  ac:{
      options: {

          laxcomma: true, // maybe we should turn this on? Why do we have these 
          curly: true,
          eqeqeq: true,
          immed: true,
          latedef: true,
          onevar: true
      },
      source: {
          src: ['module1/*.js']
      }
  },
  lib:{
      options: {
          laxcomma: true, // maybe we should turn this on? Why do we have these 
          curly: true,
          eqeqeq: true,
          immed: true,
          latedef: true
      },
      source: {
          src: ['module2/*.js']
      }
  }

}

我看到了一些堆栈溢出问题,但我只能找到 Grunt-hub 作为一个选项,我需要创建 2 个单独的文件,然后是一个 grunt hub 文件。我不想这样做,请指导我如何进行?

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    使用目标:http://gruntjs.com/configuring-tasks#task-configuration-and-targets

    grunt.initConfig({
      jshint: {
        one: {
          src: ['files/*'],
          options: { /* ... */ }
        },
        two: {
          src: ['files2/*'],
          options: { /* ... */ }
        }
      }
    });
    

    【讨论】:

    • @Kyle.. 感谢您的回答,但按照您所说的方式,每次 JsHint 都会为这两个模块执行。我希望它也具有选择性,即基于我的命令行输入,我应该能够为一个特定模块运行任务。请指导我如何通过上述方法实现这一点。提前致谢。
    • 尝试grunt jshint:onegrunt jshint:two 有选择地运行每个目标。
    • 是的,我试过了,它工作正常。感谢您的帮助。我也想对其他任务做同样的事情,然后需要使用 Registertasks 定义别名,我该怎么做?
    • 我可以注册任务... :) 现在需要尝试其他任务,希望它会以同样的方式工作。
    • 这对我不起作用。我不断收到0 files linted. Please check your ignored files. 当我不使用目标时,每个配置都会自行工作。有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    相关资源
    最近更新 更多