Search code examples
javascripthtmlgulptaskrename

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?


Solution

  • 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