- 以下是自述和示例:https://github.com/gruntjs/grunt-contrib-copy/blob/master/README.md.
- 下面是代码的相关部分(我显然无法理解)https://github.com/gruntjs/grunt-contrib-copy/blob/master/tasks/copy.js:
module.exports=函数(grunt){ "严格使用",; var path=require('path'); registerMultiTask('copy','copy files',function(){ var kindOf=grunt.util.kindOf; var options=this.options({ processContent:false, processContentExclude:[] }); var copyOptions={ 进程:options.processContent, noProcess:options.processContentExclude }; writeflags(选项,'options'); var-dest; var isExpandedPair; 变量计数={ dirs:0, 档案:0 }; this.files.forEach(函数(文件对){ isExpandedPair=filePair.orig.expand | | false; filePair.src.forEach(函数(src){ if(detectDestType(filePair.dest)=='directory'){ dest=(isExpandedPair)?filePair.dest:unixifyPath(path.join(filePair.dest,src)); }否则{ dest=filePair.dest; } if(grunt.file.isDir(src)){ grunt.verbose.writeln('Creating'+dest.cyan); grunt.file.mkdir(dest); tally.dirs++; }否则{ grunt.verbose.writeln('Copying'+src.cyan+'->'+dest.cyan); copy(src、dest、copyOptions); tally.files++; } }); });
由于expand
是Grunt的一部分,并且不特定于Grunt contrib copy,因此有关它的信息可以在Grunt的文件配置API中找到:
将
expand
设置为true
以启用以下选项:
cwd
所有src
匹配都与此路径相关(但不包括)- 相对于
cwd
要匹配的src
模式dest
目标路径前缀ext
用生成的dest
路径中的此值替换任何现有扩展名extDot
用于指示表示扩展名的句点的位置。可以采用'first'
(扩展名在文件名的第一个句点之后开始)或'last'
(扩展名在最后一个句点之后开始),默认情况下设置为'first'
plant
从生成的dest
路径中删除所有路径部分rename
为每个匹配的src
文件调用此函数(扩展名重命名和展开后)。传递dest
和匹配的src
路径,此函数必须返回一个新的dest
值。如果同一dest
多次返回,则使用它的每个src
都将添加到源数组中
此外,如果将expand
设置为true
,则似乎dest
将始终被视为目标目录