Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename all files in a folder using gulp js?

Tags:

node.js

gulp

I have a bunch of html files in a partials directory. Using gulp js, I want to minify and rename these files to .min.html. Please show me how to achieve this.

like image 1000
Melvin Avatar asked Mar 03 '14 06:03

Melvin


1 Answers

See here, using gulp-rename, if you just want to rename the files.

Something in the line of below should do:

var rename = require('gulp-rename');
gulp.src("./partials/**/*.hmtl")
.pipe(rename(function (path) {
  path.suffix += ".min";
}))
.pipe(gulp.dest("./dist"));

In order to minify, you can use gulp-htmlmin. Pretty straightforward from the documentation:

var htmlmin = require('gulp-htmlmin');

gulp.task('compress', function() {
  gulp.src('./partials/**/*.html')
    .pipe(htmlmin())
    .pipe(gulp.dest('dist'))
});

You can certainly combine the two to obtain the desired effect.

like image 64
Mangled Deutz Avatar answered Nov 15 '22 05:11

Mangled Deutz