Created
November 7, 2017 11:11
-
-
Save NevenLeung/71e6cddbb8b7c5da356cd715787aa285 to your computer and use it in GitHub Desktop.
gulpfile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp =require('gulp'), | |
useref = require('gulp-useref'), | |
uglify = require('gulp-uglify'), | |
cleancss = require('gulp-clean-css'), | |
rev = require('gulp-rev'), | |
revReplace = require('gulp-rev-replace'), | |
gulpif = require('gulp-if'); | |
gulp.task('pack', function () { | |
return gulp.src('./src/**/*.html') | |
.pipe(useref()) //pack the file in index.html with build comment | |
.pipe(gulpif('*.js', uglify())) // minify js | |
.pipe(gulpif('*.js', rev())) // append hash to the packed js file | |
.pipe(gulpif('*.css', cleancss())) // minify css | |
.pipe(gulpif('*.css', rev())) // append hash to the packed js file | |
// substitute the useref filename with the hash filename in index.html | |
.pipe(revReplace()) | |
.pipe(gulp.dest('dist')); | |
}; | |
gulp.task('default', ['pack']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment