-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
153 lines (127 loc) · 3.58 KB
/
gulpfile.babel.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
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
144
145
146
147
148
149
150
151
152
153
'use strict';
// Load plugins
import gulp from 'gulp';
import sass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import minifycss from 'gulp-minify-css';
import uglify from 'gulp-uglify';
import imagemin from 'gulp-imagemin';
import rename from 'gulp-rename';
import clean from 'gulp-clean';
import cache from 'gulp-cache';
import browserSync from 'browser-sync';
import babel from 'gulp-babel';
import del from 'del';
const reload = browserSync.reload;
const stream = browserSync.stream;
// Compile scripts
gulp.task('scripts', () => {
return gulp.src('src/javascripts/*.js')
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('build/src/javascripts'))
});
// Ensure compiling is complete before reloading
gulp.task('watch:scripts', ['scripts'], () => {
browserSync.reload();
});
// JSON
gulp.task('json', () => {
return gulp.src('src/json/*')
.pipe(gulp.dest('build/src/json'))
// Live reload after compiling
.pipe(stream({stream: true}));
});
// General images
gulp.task('images', () => {
return gulp.src('src/images/*')
.pipe(cache(imagemin()))
.pipe(gulp.dest('build/src/images'))
// Live reload after compiling
.pipe(stream({stream: true}));
});
// Card images
gulp.task('cards', () => {
return gulp.src('apps/**/*.png')
.pipe(cache(imagemin()))
.pipe(gulp.dest('build'))
// Live reload after compiling
.pipe(stream({stream: true}));
});
// SVGs
gulp.task('svgs', () => {
return gulp.src('apps/**/*.svg')
.pipe(gulp.dest('build'))
// Live reload after compiling
.pipe(stream({stream: true}));
});
// Main CSS
gulp.task('styles', () => {
return gulp.src('src/stylesheets/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(minifycss())
.pipe(gulp.dest('build/src/stylesheets'))
// Live reload after compiling scss
.pipe(stream({stream: true}))
});
// Index + Favicon
gulp.task('index', () => {
return gulp.src(['./index.html', './favicon.ico'])
.pipe(gulp.dest('build'))
});
// App views
gulp.task('views', () => {
return gulp.src('apps/**/*.html')
.pipe(gulp.dest('build'))
});
// Ensure compiling is complete before reloading
gulp.task('watch:html', ['index', 'views'], () => {
browserSync.reload();
});
// App misc
gulp.task('misc', () => {
return gulp.src(['apps/**/*.css',
'apps/**/*.js',
'apps/**/*.ttf',
'apps/**/*.woff'])
.pipe(gulp.dest('build'))
});
// Ensure compiling is complete before reloading
gulp.task('watch:misc', ['misc'], () => {
browserSync.reload();
});
// Clean
gulp.task('clean', () => {
del.sync(['build'], {read: false})
});
// Build task
gulp.task('build', ['clean', 'scripts', 'json', 'styles', 'images', 'views', 'cards', 'misc', 'index', 'svgs']);
// Start browserSync for local server
gulp.task('server', ['build'], () => {
browserSync.init({
server: "./build",
notify: false
});
})
// Default task
gulp.task('default', ['server']);
// Watch task
gulp.task('watch', ['server'], () => {
// main scss
gulp.watch('src/stylesheets/*.scss', ['styles']);
// js
gulp.watch('src/javascripts/*.js', ['watch:scripts']);
// card images
gulp.watch('apps/*/*.png', ['cards']);
// svgs
gulp.watch('apps/*/*.svg', ['svgs']);
// general images
gulp.watch('src/images/*', ['images']);
// json
gulp.watch('src/json/*', ['json']);
// per app misc
gulp.watch(['apps/**/*.css', 'apps/**/*.js', 'apps/**/*.ttf', 'apps/**/*.woff'], ['watch:misc']);
// views + index
gulp.watch(['apps/*/*.html', './index.html'], ['watch:html']);
});