-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
167 lines (151 loc) · 3.71 KB
/
gulpfile.js
File metadata and controls
167 lines (151 loc) · 3.71 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var browserSync = require('browser-sync');
var del = require('del');
var gulp = require('gulp');
var inlineCss = require('gulp-inline-css');
var imagemin = require('gulp-imagemin');
var assemble = require('fabricator-assemble');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var styleInject = require("gulp-style-inject");
var config = {
html: {
src: './src/views/**/*.html'
},
assemble: {
src: './dist/*.html',
},
styles: {
src: './src/scss/**/*.scss'
},
images: {
src: './src/images/**/*',
dest: './dist/images'
},
dest: './dist',
data: './src/data.json'
};
/**
* build
*
* Run all the neccesary tasks to make your emails
*/
gulp.task('build', function(cb) {
runSequence(['compileTemplates', 'compileStyles', 'injectStyles', 'inlineStyles', 'optimizeImages', 'postclean'], cb);
});
/**
* compileTemplates
*
* Compile all our HTML layouts and compoents to plain old HTML files.
*/
gulp.task('compileTemplates', function() {
return assemble({
dest : config.dest,
data: config.data,
keys: {
materials: 'components',
views: 'views',
docs: 'docs'
},
materials: 'src/components/*.html',
helpers : {
default: function (value, defaultValue) {
return value ? value : defaultValue;
},
}
});
});
/**
* compileStyles
*
* Converts .scss files to css. Pipes result to temporary CSS file.
*/
gulp.task('compileStyles', function() {
return gulp.src(config.styles.src)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(config.dest));
});
/**
* injectStyles
*
* Inject compiled CSS into <style> tag in template.
* This allows you to use things like :hover styles and media queries when supported
*/
gulp.task('injectStyles', ['compileTemplates', 'compileStyles'], function() {
return gulp.src(config.assemble.src)
.pipe(styleInject())
.pipe(gulp.dest(config.dest));
});
/**
* inlineStyles
*
* Take all of the CSS in the <style> tag, and add the styles as style attributes on every matching element.
* https://www.campaignmonitor.com/blog/email-marketing/2013/11/introducing-our-new-standalone-css-inliner/
*/
gulp.task('inlineStyles', ['injectStyles'], function() {
return gulp.src(config.assemble.src)
.pipe(inlineCss({
applyStyleTags: true,
applyLinkTags: true,
removeStyleTags: false,
removeLinkTags: true,
preserveMediaQueries: true
}))
.pipe(gulp.dest(config.dest));
});
/**
* optimizeImages
*
* Optimize any images you are using in your emails.
*/
gulp.task('optimizeImages', function () {
return gulp.src(config.images.src)
.pipe(imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(config.images.dest));
});
/**
* preclean
*
* Blow away previous builds before we start
*/
gulp.task('preclean', function (cb) {
del([config.dest], cb);
});
/**
* postclean
*
* Delete the compiled CSS file, since we've injected the contents into a <style> tag on every HTML file
*/
gulp.task('postclean', ['inlineStyles'], function (cb) {
del([config.dest + '/*.css'], cb);
});
/**
* serve
*
* Run in browser with live reloading when files change
*/
gulp.task('serve', function() {
browserSync({
server: {
baseDir: config.dest
},
notify: false
});
gulp.task('styles:watch', ['build'], browserSync.reload);
gulp.watch(config.styles.src, ['styles:watch']);
gulp.task('html:watch', ['build'], browserSync.reload);
gulp.watch(config.html.src, ['html:watch']);
gulp.watch(config.data, ['html:watch']);
});
/**
* default
*
* Default gulp task. Build email, then serve with kick off serve task.
*/
gulp.task('default', ['preclean'], function () {
runSequence(['build'], function () {
gulp.start('serve');
});
});