the following is the configuration file for gulpfile.js
const gulp = require("gulp") // gulp
const uglify = require("gulp-uglify") // js
const jshint = require("gulp-jshint") // js
const minifyHtml = require("gulp-minify-html") // html
const pump = require("pump")
const clean = require("gulp-clean")
const rev = require("gulp-rev")
const revCollector = require("gulp-rev-collector")
const minifyCss = require("gulp-minify-css")
const imagemin = require("gulp-imagemin")
const autoprefixer = require("gulp-autoprefixer")
const runSequence = require("run-sequence")
const rename = require("gulp-rename")
const jsSrc = "js/*.js"
const cssSrc = "css/*.css"
const htmlSrc = "*.html"
const imgSrc = "img/*.{jpg,png,gif,ico}"
gulp.task("img", function () {
return gulp.src(imgSrc)
.pipe(imagemin())
.pipe(gulp.dest("dist/img"))
})
gulp.task("clean", function (done) {
pump([
gulp.src("dist/**/*"),
clean()
], done)
})
gulp.task("js", function () { // task "minjs"
return gulp.src(jsSrc) // src
.pipe(jshint())
.pipe(uglify()) // .pipe()
.pipe(rename({suffix: ".min"}))
.pipe(rev())
.pipe(gulp.dest("dist/js"))
.pipe(rev.manifest())
.pipe(gulp.dest("dist/rev/js"))
})
gulp.task("css", function () {
return gulp.src(cssSrc)
.pipe(autoprefixer({
// browsers: ["last 2 versions"], //
cascade: true, // true
add: true, // true
remove: true, // true
flexbox: true // flexboxtrue
}))
.pipe(minifyCss())
.pipe(rename({suffix: ".min"}))
.pipe(rev())
.pipe(gulp.dest("dist/css"))
.pipe(rev.manifest())
.pipe(gulp.dest("dist/rev/css"))
})
gulp.task("copy", function () {
return gulp.src([
"**/*.*",
"!img/**/*.*",
"!js/**/*.*",
"!rev/**/*.*",
"!css/**/*.*",
"!node_modules/**/*.*",
"!gulpfile.js",
"!package.json"
])
.pipe(gulp.dest("dist"))
})
gulp.task("html", function() {
return gulp.src(htmlSrc)
.pipe(minifyHtml())
.pipe(gulp.dest("dist"))
});
gulp.task("rev-html", function () {
return gulp.src(["./dist/rev/**/*.json", "./dist/*.html"])
.pipe(revCollector({
replaceReved: true
}))
.pipe(gulp.dest("dist"))
})
gulp.task("default", function (callback) {
runSequence("clean", ["img", "js", "css", "copy", "html"], "rev-html", callback)
})
if the .pipe (rename ({suffix: ".min"}) path can be replaced successfully, how to solve the problem after renaming