【问题标题】:Shared options between targets and running multiple targets目标之间的共享选项和运行多个目标
【发布时间】:2014-03-23 01:38:41
【问题描述】:

我对咕噜声有点困惑。首先,我爱上了这个工具,但是文档(或者可能只是我自己)对此并不是很聪明。

所以我有这样的事情:

coffee:
  options:
    sourceMap: true
    files: [{
      expand: true
      cwd:    '<%= yeoman.app %>/scripts'
      src:    '{,*/}*.coffee'
      dest:   '<%= yeoman.tmp %>/scripts'
      ext:    '.js'
    }]
  test:
    files: [{
      expand: true
      cwd:    '<%= yeoman.app %>/scripts'
      src:    '{,*/}*.coffee'
      dest:   '<%= yeoman.tmp %>/scripts'
      ext:    '.js'
    }, {
      expand: true
      cwd:    '<%= yeoman.test %>/spec'
      src:    '{,*/}*.coffee'
      dest:   '<%= yeoman.tmp %>/spec'
      ext:    '.js'
    }]

我认为这在理论上应该在我的目标“dev”、“dist”和“test”之间有“共享”文件。

但据我了解,files 不应停留在选项下(为什么?)。
我也有这个:

compass:
  all:
    options:
      sassDir:                 '<%= yeoman.app %>/styles'
      cssDir:                  '<%= yeoman.tmp %>/styles'
      generatedImagesDir:      '<%= yeoman.tmp %>/images/generated'
      imagesDir:               '<%= yeoman.app %>/images'
      javascriptsDir:          '<%= yeoman.app %>/scripts'
      fontsDir:                '<%= yeoman.app %>/fonts'
      importPath:              [
        '<%= yeoman.app %>/bower_components'
        '<%= yeoman.app %>/styles'
      ]
      httpImagesPath:          '/images'
      httpGeneratedImagesPath: '/images/generated'
      httpFontsPath:           '/fonts'
      httpStylesheetsPath:     '/styles'
      httpJavascriptsPath:     '/scripts'
      relativeAssets:          true
      assetCacheBuster:        false
      bundleExec:              true
      raw: 'Sass::Script::Number.precision = 10\n'
  dist:
    options:
      environment:        'production'
      generatedImagesDir: '<%= yeoman.dist %>/images/generated'

但运行 grunt compass 运行 both grunt compass:allgrunt compass:dist 这是正常行为吗?

我肯定需要对此进行更好的解释。

【问题讨论】:

    标签: coffeescript gruntjs


    【解决方案1】:

    任务配置中的第一级可以是“子”任务。

    所以你可以通过以下方式调用它:

    grunt compass
    
    grunt compass:all
    
    grunt compass:dist
    

    当您不引用子任务时,grunt 会运行给定主任务的所有子任务。 (所以第一个运行 alldist

    否则,您可以在配置中使用这些 '' 符号引用其他部分。详情:http://gruntjs.com/api/grunt.config

    【讨论】:

    • 谢谢 Lajos,我想问其他一些细节,但你的回答已经可以了。 files 键应该保留在 options 下还是每个插件都不同?
    • options 是所有子任务的默认设置,但您可以使用子任务选项覆盖它。据我所知文件并不特殊,所以你可以在上面的选项中使用它作为子任务的默认值,但你只能在子任务中定义它
    猜你喜欢
    • 2021-07-13
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2018-03-18
    • 2012-07-22
    • 1970-01-01
    相关资源
    最近更新 更多