在gulp中移动时重命名文件?

时间:2016-11-09 15:14:34

标签: gulp

我正在获取文件并使用gulp移动它:

gulp.src('src/myfile.html')
.pipe(gulp.dest('dist'));

如何重命名文件?

1 个答案:

答案 0 :(得分:1)

尝试https://www.npmjs.com/package/gulp-rename

// rename via string 
gulp.src("./src/main/text/hello.txt")
  .pipe(rename("main/text/ciao/goodbye.md"))
  .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md 


// rename via function 
gulp.src("./src/**/hello.txt")
  .pipe(rename(function (path) {
    path.dirname += "/ciao";
    path.basename += "-goodbye";
    path.extname = ".md"
  }))
  .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md