-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulpfile.js
62 lines (53 loc) · 1.54 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
require('babel-register');
// Require the custom components and get the affected engine
require('./components')
var mjmlEngine = require('mjml')
var gulp = require('gulp')
// TODO Get rid of the temporary fix when gulp-mjml is updated
//var mjml = require('gulp-mjml')
var mjml = require('./gulp/mjml')
var del = require('del')
var browserSync = require('browser-sync').create()
var path = require('path')
var nodemon = require('gulp-nodemon')
var notifier = require('node-notifier');
var mjmlFiles = './templates/*.mjml'
var htmlFiles = './dist/*.html'
var distFolder = './dist'
var port = process.env.PORT || 8001
gulp.task('default', ['serve', 'watch'])
gulp.task('watch', ['serve'], function() {
// When HTML files change, reload browser
gulp.watch([htmlFiles], () => browserSync.reload())
// Watch any change for js (components) and mjml files
// Build in another process to use last components changes
nodemon({
script: 'build.js',
ext: 'js mjml',
ignore: 'node_modules'
})
.on('crash', function() {
notifier.notify({
title: 'MJML compilation',
message: 'It seems that something went wrong...'
})
})
})
gulp.task('serve', ['build'], function() {
return browserSync.init({
port: port,
server: {
baseDir: './'
},
reloadDelay: 2000
})
})
gulp.task('build', ['clean'], function () {
console.log('Building html files...')
return gulp.src(mjmlFiles)
.pipe(mjml(mjmlEngine))
.pipe(gulp.dest(distFolder))
})
gulp.task('clean', function() {
return del(distFolder)
})