1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| var gulp = require('gulp'); var sass = require('gulp-sass'); var prefix = require('gulp-autoprefixer'); var minifyCSS = require('gulp-minify-css'); var rename = require('gulp-rename'); var htmlmin = require('gulp-htmlmin'); var htmlclean = require('gulp-htmlclean'); var babel = require('gulp-babel'); var uglify = require('gulp-uglify'); var imagemin = require('gulp-imagemin');
gulp.task('minify-html', function() { return gulp.src('./*.html') .pipe(htmlclean()) .pipe(htmlmin({ removeComments: true, minifyJS: true, minifyCSS: true, minifyURLs: true, })) .pipe(gulp.dest('./public')); done(); });
gulp.task('compressCSS', function() { return gulp.src(['src/css/*.scss','src/css/*.css']) .pipe(sass()) .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true })) .pipe(minifyCSS()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('./public/src/css/')) .pipe(browserSync.stream()); done(); });
gulp.task('minify-js', function (done) { return gulp.src(['src/js/*.js']) .pipe(uglify()) .pipe(gulp.dest('./public/src/js/')); done(); });
gulp.task('minify-images', function() { return gulp.src('*.ico', 'src/img/*.*') .pipe(imagemin( [imagemin.gifsicle({'optimizationLevel': 3}), imagemin.optipng({'optimizationLevel': 7}), imagemin.svgo()], {'verbose': true})) .pipe(gulp.dest('./public/src/images')) });
gulp.task('font', function (done) { return gulp.src(['./font/*']) .pipe(gulp.dest('./public/font')); done(); });
gulp.task('default',gulp.series(gulp.parallel('compressCSS','minify-js', 'minify-images', 'font', 'minify-html')), function () { console.log("----------gulp Finished----------"); });
|