【问题标题】:Grunt - Task doesn't support multitask?Grunt - 任务不支持多任务?
【发布时间】:2014-04-26 06:05:24
【问题描述】:

我有这个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.

有没有办法做到这一点?

【问题讨论】:

    标签: node.js gruntjs


    【解决方案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'
        }]
      }
    },
    

    【讨论】:

    • 如果我想为每组文件设置不同的宽度/高度怎么办?
    • 这应该可以为每个任务单独调整大小。
    • 啊,没有注意到文件周围的括号。这行得通,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    相关资源
    最近更新 更多