- 以下是自述和示例: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将始终被视为目标目录