Open moahmn opened 6 years ago
change:
gulp.task('script',function(){
gulp.src('./dev/scripts/**/*.js')
.pipe(replace(/dev\/templates/g, '/publish/build'))
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('build/scripts'))
.pipe(rev.manifest())
.pipe(gulp.dest( 'rev/scripts' ));
})
to
gulp.task('script',function(){
return gulp.src('./dev/scripts/**/*.js')
.pipe(replace(/dev\/templates/g, '/publish/build'))
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('build/scripts'))
.pipe(rev.manifest())
.pipe(gulp.dest( 'rev/scripts' ));
})
var gulp = require('gulp'), uglify = require('gulp-uglify'), cleanCSS = require('gulp-clean-css'), revCollector = require('gulp-rev-collector'), rev = require('gulp-rev'), minifyHTML = require('gulp-minify-html'), autoprefixer = require('gulp-autoprefixer'), imagemin = require('gulp-imagemin'), clean = require('gulp-clean'), replace = require('gulp-replace'), gulpSequence = require('gulp-sequence');
gulp.task('script',function(){
}) gulp.task('copy', function() { return gulp.src('./dev/fonts/*/') .pipe(gulp.dest('build/fonts')) });
gulp.task('cleanCSS',function(){ return gulp.src(['./dev/styles/.css','./dev/fonts/.css']) .pipe(rev()) .pipe(cleanCSS({ compatibility:'ie9', })) .pipe(autoprefixer({ browsers: ['> 5%'], cascade: false })) .pipe(gulp.dest('build/styles')) .pipe( rev.manifest()) .pipe( gulp.dest( 'rev/styles' )); })
//gulp.task('rev',['cleanCSS','script'],function(){ gulp.task('rev',function(){ return gulp.src(['rev/*/.json','dev/templates/*.html','./index.html'])// .pipe(revCollector({ replaceReved: true, dirReplacements:{ 'dev/scripts/':'./scripts/', 'dev/styles':'./styles', 'dev/fonts':'./styles', } })) .pipe(replace(/dev\/images\//g, 'images/')) .pipe( minifyHTML({ empty:true, spare:true })) .pipe(gulp.dest('./build'))
}) gulp.task('clean', function () { return gulp.src(['./build','./rev'], {read: false}) .pipe(clean()); }); gulp.task('imagemin',function(){ gulp.src('dev/images/*/') .pipe(imagemin([ imagemin.gifsicle({interlaced: true}), imagemin.jpegtran({progressive: true}), imagemin.optipng({optimizationLevel: 5}), imagemin.svgo({plugins: [{removeViewBox: true}]})],{ verbose:true })) .pipe(gulp.dest('build/images')) })
//gulp.task('build',['rev','imagemin','copy'])
gulp.task('build',gulpSequence('clean','script','cleanCSS',['imagemin','copy'],'rev'))
this is my gulpfile.js ,sometime it's work well,all path can replace right . but sometime,the css path can be replace,but js path can't be replace . sometime success,sometime fail,that why ?if i run task(expect rev task)first,and then run rev task,it's work well,but i want run task once and everthing is gone;i hope your help,thank!