1

我想编写一个 Grunt 任务,在构建期间,它将复制我拥有的所有 .html 文件并在 /dist 中制作它的 .asp 版本。

我一直在尝试使用grunt-contrib-copy来完成此任务,这就是我所拥有的:

copy: {
  //some other tasks that work...

  //copy an .asp version of all .html files
  asp: {
    files: [{
      expand: true,
      dot: true,
      cwd: '<%= config.app %>',
      src: ['{,*/}*.html'],
      dest: '<%= config.dist %>',
      option: {
        process: function (content, srcpath) {
          return srcpath.replace(".asp");
        }
      }
    }]
  } //end asp task
},

我知道该process函数实际上并不正确......我尝试了一些不同的正则表达式以使其无济于事。当我运行asp任务时,Grunt CLI 说我已经复制了 2 个文件,但是找不到它们。任何帮助表示赞赏。

4

1 回答 1

7

你可以使用rename函数来做到这一点。

例如:

copy: {
  //some other tasks that work...

  //copy an .asp version of all .html files
  asp: {
    files: [{
      expand: true,
      dot: true,
      cwd: '<%= config.app %>',
      src: ['{,*/}*.html'],
      dest: '<%= config.dist %>',
      rename: function(dest, src) {
         return dest + src.replace(/\.html$/, ".asp");
      }
    }]
  } //end asp task
},

这应该有效。

于 2015-04-01T21:04:38.573 回答