-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
66 lines (56 loc) · 1.88 KB
/
gulpfile.js
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
var gulp = require('gulp');
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
var htmlmin = require('gulp-htmlmin');
gulp.task('hello', function() {
console.log("Hello, world!");
});
gulp.task('useref', function() {
return gulp.src('app/*.html') /* Load all HTML files */
.pipe(useref()) /* Combine files into one */
.pipe(gulpIf('*.js', uglify())) /* minify javascript files */
.pipe(gulpIf('*.css', cssnano())) /* minify css files */
.pipe(gulpIf('*.html', htmlmin({ collapseWhitespace: false, minifyJS: false, minifyCSS: false }))) /* also minify html */
.pipe(gulp.dest('html')) /* Write out to 'html' output directory */
});
gulp.task('cpjson', function() {
return gulp.src('app/*.json')
.pipe(gulp.dest('html'))
});
gulp.task('cpexamples', function() {
return gulp.src('app/examples/**/*')
.pipe(gulp.dest('html/examples'))
});
gulp.task('cpimages', function() {
return gulp.src('app/images/**/*.{png,gif,jpg,svg}')
.pipe(imagemin())
.pipe(gulp.dest('html/images'))
});
gulp.task('clean:html', function() {
return del.sync('html');
});
gulp.task('cache:clear', function(callback) {
return cache.clearAll(callback);
});
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: 'app'
}
})
});
gulp.task('watch', ['browserSync'], function() {
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
});
gulp.task('build', function(callback) {
runSequence('clean:html', ['useref', 'cpimages', 'cpjson', 'cpexamples'],
callback
);
});