forked from raazmi/bootstrap-starter-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
212 lines (157 loc) · 4.59 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var cleancss = require('gulp-clean-css');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var autoPrefixer = require('gulp-autoprefixer');
var gulpInject = require('gulp-inject');
var tinypngs = require('gulp-tinypng-compress');
/*************************
DEFAULT TASKS
**************************/
/* Serve */
function serve(done) {
browserSync.init({
server: {
baseDir: './src'
}
})
done();
}
/* Sass Compiler */
function sassCompile(done) {
gulp.src('./src/assets/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(autoPrefixer('last 10 versions'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./src/assets/css'))
.pipe(browserSync.reload({
stream: true
}));
done();
}
/* Reload */
function reload(done) {
browserSync.reload();
done();
}
/* Watch Files */
function watchFiles(done) {
gulp.watch('./src/assets/sass/**/*.scss', sassCompile);
gulp.watch('./src/*.html', reload);
gulp.watch('./src/assets/js/**/*.js', reload);
done();
}
/*************************
DIST TASKS
**************************/
/* Optimize Images */
function distImageOptimize(done) {
gulp.src('./src/assets/images/**/*.{png,jpg,jpeg}')
.pipe(tinypngs({
key: 'xYMAfkMBuKzyZZdshqwIuYfv8I8bmWBe',
sigFile: './src/images/.tinypng-sigs',
log: true
}))
.pipe(gulp.dest('./dist/assets/images'));
gulp.src('./src/assets/images/**/*.{gif,ico,svg}')
.pipe(gulp.dest('./dist/assets/images'));
done();
}
/* Move Fonts */
function distFonts(done) {
gulp.src('./src/assets/fonts/*').pipe(gulp.dest('./dist/assets/fonts'));
done();
}
/* Move css with minify */
function distCss(done) {
gulp.src('./src/assets/css/**/*.css')
.pipe(cleancss())
.pipe(gulp.dest('./dist/assets/css'));
gulp.src('./src/assets/css/style.css')
.pipe(cleancss())
.pipe(gulp.dest('./dist/assets/css'));
done();
}
/* Move js with minify */
function distJs(done) {
gulp.src('./src/assets/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('./dist/assets/js'));
done();
}
/* Move HTML files */
function distHTML(done) {
gulp.src('./src/*.html')
.pipe(gulp.dest('dist'));
done();
}
/*************************
BUILD TASKS
**************************/
/* Optimize Images */
function buildImageOptimize(done) {
gulp.src('./src/assets/images/**/*.{png,jpg,jpeg}')
.pipe(tinypngs({
key: 'xYMAfkMBuKzyZZdshqwIuYfv8I8bmWBe',
sigFile: './src/images/.tinypng-sigs',
log: true
}))
.pipe(gulp.dest('./build/assets/images'));
gulp.src('./src/assets/images/**/*.{gif,ico,svg}')
.pipe(gulp.dest('./build/assets/images'));
done();
}
/* Move Fonts */
function buildFonts(done) {
gulp.src('./src/assets/fonts/*').pipe(gulp.dest('./build/assets/fonts'));
done();
}
function buildCss(done) {
gulp.src('./src/assets/css/style.css')
.pipe(cleancss())
.pipe(gulp.dest('./build/assets/css'));
gulp.src('./src/assets/css/vendors/*.css')
.pipe(concat('plugins.min.css'))
.pipe(cleancss())
.pipe(gulp.dest('./build/assets/css/vendors'));
done();
}
/* Move js with minify */
function buildJs(done) {
gulp.src('./src/assets/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('./build/assets/js'));
gulp.src('./src/assets/js/vendors/*.js')
.pipe(concat('plugins.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./build/assets/js/vendors'));
done();
}
/* Move HTML files */
function buildHTML(done) {
gulp.src('./src/*.html')
.pipe(gulp.dest('build'));
done();
}
/* Inject Files */
function injectFiles(done) {
gulp.src('./build/*.html')
.pipe(gulpInject(gulp.src(['./build/assets/css/**', './build/assets/js/**'], {
read: false
}), {
relative: true
}))
.pipe(gulp.dest('./build'));
done();
}
/* Tasks */
gulp.task("default", gulp.parallel(serve, sassCompile, watchFiles));
gulp.task("dist", gulp.parallel(distImageOptimize, distFonts, distCss, distJs, distHTML));
gulp.task("build", gulp.series(buildHTML, buildFonts, buildCss, buildJs, buildImageOptimize));
gulp.task("buildfinal", injectFiles);