简体   繁体   中英

Gulp-rename change name each file in folder

I used Gulp in my project and I installed gulp-rename plugin. I have folder CSS and dist and in the second folder I have a few CSS files.

I want to change their name with name.css on name.min.css , but the task which I use not copy file name. There is my code:

gulp.task('rename', function () {
    return gulp.src('./dist/*.css')
        .pipe(rename('/*.min.css'))
        .pipe(gulp.dest('./css'));
});

For example:

I have three css file in dist: abc.css , mno.css and xyz.css and I use this task. It renames and remote files but without a name. I want have abc.min.css but I have *.min.css , etc.

Can you help me?

As per the docs , you need to use the callback rename:

gulp.src("./css/*.css")
  .pipe(rename(function (path) {
    path.basename += ".min";
    path.extname = ".css";
  }))
  .pipe(gulp.dest("./dist"));

// ./dist/file.min.css

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM