[英]gulp rename doesn't work as expected
I am trying to use gulp rename to files in a stream. 我正在尝试使用gulp重命名流中的文件。 This is my code: 这是我的代码:
var jsFiles = gulp.src(['app/scripts/modules.js', 'app/scripts/**/*.js'])
.pipe(map(function(path, callback) {
path.dirname = Path.join('./dist', 'scripts', path.basename + path.extname);
}));
I was hopping to get the following conversion: 我希望获得以下转换:
app/scripts/* -> dist/scripts/*
app/scripts/abc/* -> dist/scripts/abc/*
Instead, I got: 相反,我得到了:
app/scripts/* -> app/scripts/dist/scripts/*
app/scripts/abc/* -> app/scripts/dist/scripts/abc/*
What is wrong with this code? 此代码有什么问题? Anyway, an alternative is something like the map function. 无论如何,替代方法是类似于map函数。 I found this: https://github.com/dominictarr/map-stream but I can't figure out how to use it for this need. 我发现了这一点: https : //github.com/dominictarr/map-stream,但我不知道如何使用它来满足这一需求。
You can specify a base in gulp.src
to determine the starting directory of the paths of matched files. 您可以在gulp.src
指定一个基数,以确定匹配文件路径的起始目录。 By default it's the process.cwd()
, but you can change it to whatever you want. 默认情况下是process.cwd()
,但您可以将其更改为所需的任何值。
So the relative paths will crop all the base
part you have specified. 因此,相对路径将裁剪您指定的所有base
零件。
var jsFiles = gulp.src(['app/scripts/modules.js', 'app/scripts/**/*.js'], { base: 'app/scripts' })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.