-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
143 lines (119 loc) · 3.33 KB
/
gulpfile.js
File metadata and controls
143 lines (119 loc) · 3.33 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var gulp = require('gulp'),
pug = require('gulp-pug'),
del = require('del'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
runSequence = require('run-sequence'),
$ = require('gulp-load-plugins')({
lazy: true
});
var src = './src';
var paths = {
src: src,
dist: './dist',
pug: [
'!' + src + '/pug/include/*.pug',
src + '/pug/**/*.pug'
],
sass: src + '/sass/**/*.scss',
js: src + '/js/**/*.js',
media: src + '/media/*',
img: src + '/img/**/*',
fonts: src + '/fonts/**/*',
static: src + '/*.{txt,xml}'
};
// List tasks
gulp.task('default', ['help']);
gulp.task('help', $.taskListing.withFilters(null, 'default'));
// Build the app; clean, compile
gulp.task('build', buildTask);
// Local server for development; clean, compile, server + watching
gulp.task('serve', devServerTask);
// Clean the dist dir
gulp.task('clean', cleanTask);
//////////////////////////////////////
function devServerTask() {
return runSequence('clean', 'compile', watchServer);
///////////
function watchServer(){
// Start the server
browserSync.init({
server: {
baseDir: paths.dist,
serveStaticOptions: {
// If there isn't an extension try .html
extensions: ['html']
},
}
});
// Start watching
gulp.watch(paths.pug, ['compile_views']);
gulp.watch(paths.js, ['compile_js']);
gulp.watch(paths.sass, ['compile_sass']);
}
}
function buildTask() {
return runSequence('clean', 'compile');
}
function cleanTask() {
return del([paths.dist]);
}
// Compile from src to dist
gulp.task('compile', ['compile_views', 'compile_sass', 'compile_js', 'compile_media', 'compile_static']);
// Compile pug templates
gulp.task('compile_views', function() {
return gulp.src(paths.pug)
.pipe($.pug({
pretty: true
}))
.pipe(gulp.dest(paths.dist))
.pipe(reload({
stream: true
}));
});
// Compile sass into CSS
gulp.task('compile_sass', function() {
return gulp.src(paths.sass)
.pipe($.sass())
.pipe(gulp.dest(paths.dist + '/css'))
.pipe(reload({
stream: true
}));
});
// Compile js
gulp.task('compile_js', function() {
return gulp.src(paths.js)
//.pipe($.concat('main.js'))
.pipe(gulp.dest(paths.dist + '/js'))
.pipe(reload({
stream: true
}));
});
// Compile media files
gulp.task('compile_media', ['compile_media:generic', 'compile_media:img', 'compile_media:fonts']);
gulp.task('compile_media:generic', function() {
return gulp.src(paths.media)
.pipe(gulp.dest(paths.dist + '/media'))
.pipe(reload({
stream: true
}));
});
gulp.task('compile_media:img', function() {
return gulp.src(paths.img)
.pipe(gulp.dest(paths.dist + '/img'))
.pipe(reload({
stream: true
}));
});
gulp.task('compile_media:fonts', function() {
return gulp.src(paths.fonts)
.pipe(gulp.dest(paths.dist + '/fonts'))
.pipe(reload({
stream: true
}));
});
// Compile
gulp.task('compile_static', function() {
return gulp.src(paths.static)
.pipe(gulp.dest(paths.dist));
});