-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
148 lines (110 loc) · 2.99 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
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
/*global -$ */
'use strict';
// GULP CONFIG
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var fs = require("fs");
// Badly named tasks
var awspublish = require('gulp-awspublish');
var minifyHTML = require('gulp-minify-html');
var minifyCss = require('gulp-minify-css');
// Load project config file
// var appConfig = require('./gulp-config.json');
// *
// HTML
gulp.task('html', function () {
// Set HTML minification options
var minifyOptions = {
quotes:true
};
return gulp.src('./source/html/build.html')
.pipe($.premailer())
.pipe(minifyHTML(minifyOptions))
.pipe($.rename("index.html"))
.pipe(gulp.dest('./build'))
.pipe(browserSync.reload({stream:true}))
.pipe($.notify("HTML processing complete"));
});
// CSS
gulp.task('css', function () {
return gulp.src('source/scss/app.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'nested',
precision: 10,
includePaths: ['.'],
onError: console.error.bind(console, 'Sass error:')
}))
.pipe($.postcss([
require('autoprefixer-core')({browsers: ['last 2 version']})
]))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('./build/css'))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe($.rename("app.min.css"))
.pipe(gulp.dest('./build/css'))
.pipe(browserSync.reload({stream:true}))
.pipe($.notify("CSS compile complete"));
});
// Images
gulp.task('images', function () {
return gulp.src('source/images/**/*')
.pipe($.imagemin({
progressive: true,
interlaced: true,
svgoPlugins: [{cleanupIDs: false}]
}))
.pipe(gulp.dest('build/images'))
.pipe(browserSync.reload({stream:true}))
.pipe($.notify("Image processing complete"));
});
// *
// BUILD TASKS
// Clean task
gulp.task('clean', require('del').bind(null, ['build']));
// Build task
gulp.task('build', gulp.series('css', 'html', 'images'), function () {
});
// Clean & build
gulp.task('default', gulp.series('clean', 'build'), function () {});
// *
// WATCH TASKS
// Browser-Sync task
gulp.task('browser-sync', function (done) {
var files = [
'build/index.html'
];
browserSync.init(files, {
server: {
baseDir: './build'
}
});
done()
});
// Watch task
gulp.task('watch', function() {
gulp.watch('source/html/**/*.*', gulp.series('html'));
gulp.watch('source/scss/**/*.*', gulp.series('css'));
gulp.watch('source/images/**/*.*', gulp.series('images'));
});
// Localhost server & build
gulp.task('dev', gulp.series('build', 'browser-sync', 'watch'), function () {
});
// *
// PUBLISH TASKS
// Publish the app to S3
gulp.task('publish-images', function() {
// create a new publisher
var publisher = awspublish.create({
"key": "",
"secret": "",
"bucket": "",
"region": ""
});
return gulp.src('build/images/**/*.*')
.pipe(publisher.publish())
.pipe(publisher.cache())
.pipe($.awspublish.reporter());
});