Skip to content

Instantly share code, notes, and snippets.

@NevenLeung
Created November 7, 2017 11:11
Show Gist options
  • Save NevenLeung/71e6cddbb8b7c5da356cd715787aa285 to your computer and use it in GitHub Desktop.
Save NevenLeung/71e6cddbb8b7c5da356cd715787aa285 to your computer and use it in GitHub Desktop.
gulpfile.js
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