Grunt - 任务不支持多任务吗?

时间:2014-04-26 06:05:25

标签: node.js gruntjs

我有一个image_resize任务,我在一组文件上运行,但我想在另一组文件上再次运行它。我尝试过以下方法:

image_resize: {
  task1: {
    options: {
      width: 32,
      height: 32,
      overwrite: true
    },
    files: {
      expand: true,
      cwd: 'some cwd',
      src: ['*.png'],
      dest: 'some dest'
    }
  },
  task2: {
    options: {
      width: 32,
      height: 32,
      overwrite: true
    },
    files: {
      expand: true,
      cwd: 'some cwd',
      src: ['*.png'],
      dest: 'some dest'
    }
  }
},

但我收到错误:Warning: Object true has no method 'indexOf' Use --force to continue.

有没有办法这样做?

1 个答案:

答案 0 :(得分:1)

如果您使用grunt-image-resize,请更改为files:,以便它们是对象数组而不是单个对象。这样做会将它们放入files array format

image_resize: {
  task1: {
    options: {
      width: 32,
      height: 32,
      overwrite: true
    },
    files: [{
      expand: true,
      cwd: 'some cwd',
      src: ['*.png'],
      dest: 'some dest'
    }]
  },
  task2: {
    options: {
      width: 32,
      height: 32,
      overwrite: true
    },
    files: [{
      expand: true,
      cwd: 'some cwd',
      src: ['*.png'],
      dest: 'some dest'
    }]
  }
},