在YAML中仅定义一个对象的数组

时间:2013-12-23 08:57:45

标签: javascript gruntjs yaml

我正在尝试使用load-grunt-config来组织更好的Grunt任务。

到目前为止,我对此没有任何问题。现在,我正在尝试配置类似imagemin的内容。

所以,基本上这是我试图在YAML中复制的结构:

dynamic: {                         // Another target
  files: [{
    expand: true,                  // Enable dynamic expansion
    cwd: 'src/',                   // Src matches are relative to this path
    src: ['**/*.{png,jpg,gif}'],   // Actual patterns to match
    dest: 'dist/'                  // Destination path prefix
  }]
}

这是我的尝试:

images:
  files: [
    expand: true
    cwd: '<%= ui %>/img/'
    src:
      - '**/*.{png,jpg,gif}'
    dest: '<%= dist %>/img'
  ]

然而,由于插件无法获取正确的数据而导致失败,因此必定存在错误。

>> JS-YAML: missed comma between flow collection entries in "grunt/imagemin.yaml" at line 4, column 8:
>>         cwd: '<%= ui %>/img/'
>>      

有谁知道可能出现什么问题?

1 个答案:

答案 0 :(得分:2)

括号仅适用于在线列表。您的文件列表应如下所示:

images:
  files: 
    - expand: true
      cwd: '<%= ui %>/img/'
      src:
        - '**/*.{png,jpg,gif}'
      dest: '<%= dist %>/img'

您可以使用this之类的在线解析器测试您的YAML的正确语法。

相关问题