Grunt副本需要有关如何简化任务的建议

时间:2013-09-27 17:30:51

标签: gruntjs yeoman grunt-contrib-copy

我在Gruntfile中使用Grunt复制任务。该项目由Yeoman创建。

我正在寻找有关如何简化任务定义的建议。您会注意到每个文件集的expand和dest字段是相同的。有没有办法可以简化这个?我可以使用选项吗?

这是我的任务

copy: {
  componentsToTmp: {
    files: [
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-bootstrap',
        dest: '<%= yeoman.tmp %>/js',
        src: ['ui-bootstrap-tpls.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-cookies',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-cookies.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-l10n/build',
        dest: '<%= yeoman.tmp %>/js',
        src: ['l10n.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-local-storage',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-local-storage.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-resource',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-resource.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-sanitize',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-sanitize.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-ui/build',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-ui.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angularjs-gravatardirective/src',
        dest: '<%= yeoman.tmp %>/js',
        src: ['md5-service.min.js', 'gravatar-directive.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/bootstrap/bootstrap/js',
        dest: '<%= yeoman.tmp %>/js',
        src: ['bootstrap.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/jquery',
        dest: '<%= yeoman.tmp %>/js',
        src: ['jquery.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/jquery-ui/ui/minified',
        dest: '<%= yeoman.tmp %>/js',
        src: ['jquery-ui.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/momentjs/min',
        dest: '<%= yeoman.tmp %>/js',
        src: ['moment.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/qrcode',
        dest: '<%= yeoman.tmp %>/js',
        src: ['qrcode.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/underscore',
        dest: '<%= yeoman.tmp %>/js',
        src: ['underscore-min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.app %>/angular-local-storage-obscure',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-local-storage-obscure.js']
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:1)

这样的东西?

copy: {
  components: {
    files: [{
      src: [
        '<%= yeoman.app %>/angular-local-storage-obscure/angular-local-storage-obscure.js',
        '<%= yeoman.components %>/underscore/underscore-min.js',
        '<%= yeoman.components %>/qrcode/qrcode.min.js',
        '<%= yeoman.components %>/momentjs/min/moment.min.js',
        '<%= yeoman.components %>/jquery-ui/ui/minified/jquery-ui.min.js',
        '<%= yeoman.components %>/jquery/jquery.min.js',
        '<%= yeoman.components %>/bootstrap/bootstrap/js/bootstrap.min.js', // etc
      ],
      dest: '<%= yeoman.tmp %>/js',
      expand: true,
      flatten: true,
      filter: 'isFile'
    }]
  }
}