本文介绍了Gulp:复制时从源目录中重命名某个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文件夹复制到另一个目标,并在同一个进程中重命名某个文件。
I would like to copy a folder to another destination and rename a certain file in the same process.
gulp.task('deploy',function(){
gulp.src(['xxx / ** / *' ])。pipe(gulp.dest('yyy'));
});
我能够复制文件夹结束了,但我该如何重命名文件?
I am able to copy the folder over just fine but how would I go about renaming the file?
源文件夹结构:
Source folder structure:
- xxx (root)
- scripts
- config
- app.config.local.js (would like to rename this file as app.config.js)
- app.config.dev.js
推荐答案
您可以使用插件,以确保重命名只适用于一个特定的文件:
You can use the gulp-rename
plugin to rename files and the gulp-if
plugin to make sure the renaming is only applied to one particular file:
var gulp = require('gulp');
var rename = require('gulp-rename');
var _if = require('gulp-if');
gulp.task('deploy', function() {
return gulp.src(['xxx/**/*'])
.pipe(_if('**/app.config.local.js', rename({basename:'app.config'})))
.pipe(gulp.dest('yyy'));
});
这篇关于Gulp:复制时从源目录中重命名某个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!