-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
85 lines (69 loc) · 1.9 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
'use strict';
import gulp from 'gulp';
import babel from 'gulp-babel';
import imagemin from 'gulp-imagemin';
import mjml from 'gulp-mjml';
import newer from 'gulp-newer';
import browserSync from 'browser-sync';
import del from 'del';
// Simple config: just set up paths for everything
const basePaths = {
src: './src/',
dist: './dist/',
};
const paths = {
html: {
src: basePaths.src + '*.mjml',
},
images: {
src: basePaths.src + 'img/*',
dist: basePaths.dist + 'img/'
}
};
//
// `generateHtml` function:
// Transform the MJML files using `gulp-mjml` into HTML files
// Waiting for the process to be `done` before reloading the browsers
//
export const generateHtml = (done) => {
gulp.src(paths.html.src)
.pipe(mjml())
.pipe(gulp.dest(basePaths.dist));
browserSync.reload();
done();
};
//
// `images` function:
// Get all the new images (gulp-newer), compress them through imagemin,
// throw them in the `dist` folder & then inject them with BrowserSync
//
export const images = (done) => {
gulp.src(paths.images.src)
.pipe(newer(paths.images.dist))
.pipe(imagemin({
verbose: true
}))
.pipe(gulp.dest(paths.images.dist))
.pipe(browserSync.stream())
done();
}
//
// `watch` function:
// Start a BrowserSync server on the `dist` folder which will listen
// to the changes on html & images generated
//
export const watch = () => {
browserSync.init({
server: basePaths.dist
})
gulp.watch(paths.html.src, generateHtml);
gulp.watch(paths.images.src, images);
};
// Simple clean task, deleting the `dist` folder
gulp.task('clean', () =>
del([ basePaths.dist ])
);
// Default task: clean `dist/` folder & then run generateHtml & images tasks
gulp.task('default', gulp.series('clean', gulp.parallel(generateHtml, images)));
// Watch task: refering to the `watch` function - see above
gulp.task('watch', watch);