如何使用gulp js重命名文件夹中的所有文件?

时间:2022-10-17 15:57:07

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.

我在partials目录中有一堆html文件。使用gulp js,我想缩小并将这些文件重命名为.min.html。请告诉我如何实现这一目标。

1 个解决方案

#1


18  

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

如果您只想重命名文件,请参阅此处,使用gulp-rename。

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:

为了缩小,你可以使用gulp-htmlmin。从文档中非常简单:

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.

你当然可以将两者结合起来以获得所需的效果。

#1


18  

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

如果您只想重命名文件,请参阅此处,使用gulp-rename。

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:

为了缩小,你可以使用gulp-htmlmin。从文档中非常简单:

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.

你当然可以将两者结合起来以获得所需的效果。