Gulp: Rename certain file from source directory while copying

℡╲_俬逩灬. 提交于 2019-12-08 11:26:13

问题


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

回答1:


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'));
});


来源:https://stackoverflow.com/questions/39113143/gulp-rename-certain-file-from-source-directory-while-copying

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!