-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
111 lines (96 loc) · 2.28 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var gulp = require('gulp'),
del = require('del'),
sass = require('gulp-sass'),
pug = require('gulp-pug'),
uglify = require('gulp-uglify'),
pump = require('pump'),
webserver = require('gulp-webserver'),
sourcemaps = require('gulp-sourcemaps'),
prefix = require('gulp-autoprefixer');
/*
For shipping/building production code
*/
gulp.task('clean', () => {
return del([
'build/*' // clear the 'build' directory
]);
});
gulp.task('sass', () => {
return gulp.src('src/styles/*.scss')
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(prefix('last 2 versions'))
.pipe(gulp.dest('build'))
});
gulp.task('pug', () => {
return gulp.src('src/*.pug')
.pipe(pug({
pretty: false
}))
.pipe(gulp.dest('build'));
});
gulp.task('uglify', (cb) => {
pump([
gulp.src('src/js/*.js'),
uglify(),
gulp.dest('build')
],
cb
);
});
gulp.task('webserver', () => {
gulp.src('build')
.pipe(webserver({
livereload: true,
directoryListing: false,
open: true,
}));
});
gulp.task('default', ['clean', 'sass', 'pug', 'uglify', 'webserver'], () => {
gulp.watch(['src/styles/*.scss'], ['sass'])
gulp.watch(['src/*.pug'], ['pug'])
gulp.watch(['src/js/*.js'], ['uglify'])
});
/*
Developer options
*/
gulp.task('cleanDev', () => {
return del([
'build/*' // clear the 'build' directory
]);
});
gulp.task('pugDev', () => {
return gulp.src('src/*.pug')
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('build'));
});
gulp.task('sassDev', () => {
return gulp.src('src/styles/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(prefix('last 2 versions'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build'));
});
// copy JS exactly for easier debugging
gulp.task('jscopy', () => gulp
.src('src/js/*.js')
.pipe(gulp.dest('build')));
gulp.task('webDev', () => {
gulp.src('build')
.pipe(webserver({
livereload: true,
directoryListing: false,
open: true,
}));
});
gulp.task('dev', ['cleanDev', 'sassDev', 'pugDev', 'jscopy', 'webDev'], () => {
gulp.watch(['src/styles/*.scss'], ['sass'])
gulp.watch(['src/*.pug'], ['pug'])
gulp.watch(['src/js/*.js'], ['jscopy'])
});