下面是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 // 为flexbox属性添加前缀,默认true
}))
.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)
})
如果去除 .pipe(rename({suffix: '.min'})) 路径是可以替换成功的,怎么解决重命名之后的问题