-
Notifications
You must be signed in to change notification settings - Fork 26
/
gulpfile.js
88 lines (77 loc) · 2.18 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var gulp = require('gulp')
var browserSync = require('browser-sync').create();
var plumber = require('gulp-plumber')
var liquid = require('gulp-liquify')
var prettify = require('gulp-jsbeautifier')
var uglify = require('gulp-uglify')
var sass = require('gulp-sass')
var rename = require('gulp-rename')
var autoprefixer = require('gulp-autoprefixer')
var decache = require('decache')
gulp.task('scripts', function () {
return gulp.src('./src/js/scripts.js')
.pipe(plumber(plumber({
errorHandler: function (err) {
console.log(err)
this.emit('end')
}
})))
.pipe(uglify({
preserveComments: 'license'
}))
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('js'))
})
gulp.task('styles', function () {
return gulp.src('./src/scss/index.scss')
.pipe(plumber(plumber({
errorHandler: function (err) {
console.log(err)
this.emit('end')
}
})))
.pipe(sass({outputStyle: 'compressed'}))
.pipe(autoprefixer())
.pipe(gulp.dest('css'))
})
gulp.task('templates', function () {
var root = './src/templates/'
decache('./src/data.js')
var data = require('./src/data.js')
return gulp.src(root + 'index.html')
.pipe(liquid(data))
.pipe(prettify())
.pipe(rename('index.html'))
.pipe(gulp.dest('./'))
})
gulp.task('watch', ['scripts', 'styles', 'templates'], function () {
gulp.watch('src/js/*.js', ['scripts'])
gulp.watch('src/scss/*.scss', ['styles'])
gulp.watch(['src/templates/**/*.html', 'src/data.js'], ['templates'])
})
gulp.task('serve', ['scripts', 'styles', 'templates'], function() {
browserSync.init({
server: {
baseDir: "./"
},
open: true
})
gulp.watch('src/js/*.js', ['scripts'])
gulp.watch('src/scss/*.scss', ['styles'])
gulp.watch(['src/templates/**/*.html', 'src/data.js'], ['templates']);
gulp.watch('index.html', function () {
gulp.src('index.html').pipe(browserSync.stream())
})
gulp.watch('css/index.css', function () {
gulp.src('css/index.css').pipe(browserSync.stream())
})
})
gulp.task('webserver', function() {
gulp.src('app')
.pipe(webserver({
livereload: true,
directoryListing: true,
open: true
}))
})
gulp.task('build', ['scripts', 'styles', 'templates'])