-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
78 lines (67 loc) · 1.81 KB
/
gulpfile.js
File metadata and controls
78 lines (67 loc) · 1.81 KB
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
71
72
73
74
75
76
77
78
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
var spa = require("browser-sync-spa");
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
gulp.task('build', function (callback) {
runSequence('clean:dist',
['images', 'compress'],
callback
)
})
gulp.task('default', function (callback) {
runSequence(['clean:dist','images', 'copy', 'compress', 'browserSync', 'watch'],
callback
)
})
gulp.task('clean:dist', function() {
return del.sync('dist');
})
gulp.task('cache:clear', function (callback) {
return cache.clearAll(callback)
})
// Gulp watch syntax
gulp.task('watch', ['browserSync'], function(){
gulp.watch('app/*.html', ['copy'], browserSync.reload);
gulp.watch('app/js/*.js', ['compress']);
})
gulp.task('compress', function() {
gulp.src('app/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('copy', function() {
gulp.src('app/*.html')
.pipe(gulp.dest('dist/'))
.pipe(browserSync.reload({
stream: true
}))
});
browserSync.use(spa({
// Options to pass to connect-history-api-fallback.
// If your application already provides fallback urls (such as an existing proxy server),
// this value can be set to false to omit using the connect-history-api-fallback middleware entirely.
history: {
index: '/index.html'
}
}));
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: 'dist'
},
})
})
gulp.task('images', function(){
return gulp.src('app/assets/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('dist/assets'))
});