【问题标题】:Grunt copy need suggestion for how to simplify taskGrunt 副本需要有关如何简化任务的建议
【发布时间】:2013-09-27 17:30:50
【问题描述】:

我在 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']
      }
    ]
  }
}

【问题讨论】:

    标签: gruntjs yeoman grunt-contrib-copy


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

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-11-16
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      相关资源
      最近更新 更多