forked from andrewalexeich/gulp-pug-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
executable file
·292 lines (273 loc) · 6.68 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
"use strict";
import webpack from "webpack";
import webpackStream from "webpack-stream";
import gulp from "gulp";
import gulpif from "gulp-if";
import browsersync from "browser-sync";
import autoprefixer from "gulp-autoprefixer";
import pug from "gulp-pug";
import pugbem from "gulp-pugbem";
import sass from "gulp-sass";
import groupmediaqueries from "gulp-group-css-media-queries";
import mincss from "gulp-clean-css";
import sourcemaps from "gulp-sourcemaps";
import rename from "gulp-rename";
import imagemin from "gulp-imagemin";
import imageminPngquant from "imagemin-pngquant";
import imageminZopfli from "imagemin-zopfli";
import imageminMozjpeg from "imagemin-mozjpeg";
import imageminGiflossy from "imagemin-giflossy";
import imageminWebp from "imagemin-webp";
import webp from "gulp-webp";
import favicons from "gulp-favicons";
import replace from "gulp-replace";
import plumber from "gulp-plumber";
import debug from "gulp-debug";
import clean from "gulp-clean";
import yargs from "yargs";
const webpackConfig = require("./webpack.config.js"),
argv = yargs.argv,
production = !!argv.production,
smartgrid = require("smart-grid"),
paths = {
views: {
src: [
"./src/views/index.pug",
"./src/pages/*.pug"
],
dist: "./dist/",
watch: [
"./src/blocks/**/*.pug",
"./src/pages/**/*.pug",
"./src/views/**/*.pug"
]
},
styles: {
src: "./src/styles/main.scss",
dist: "./dist/styles/",
watch: [
"./src/blocks/**/*.scss",
"./src/styles/**/*.scss"
]
},
scripts: {
src: "./src/js/index.js",
dist: "./dist/js/",
watch: [
"./src/blocks/**/*.js",
"./src/js/**/*.js"
]
},
images: {
src: [
"./src/img/**/*.{jpg,jpeg,png,gif,svg}",
"!./src/img/svg/*.svg",
"!./src/img/favicon.{jpg,jpeg,png,gif}"
],
dist: "./dist/img/",
watch: "./src/img/**/*.{jpg,jpeg,png,gif,svg}"
},
webp: {
src: "./src/img/**/*_webp.{jpg,jpeg,png}",
dist: "./dist/img/",
watch: "./src/img/**/*_webp.{jpg,jpeg,png}"
},
fonts: {
src: "./src/fonts/**/*.{ttf,otf,woff,woff2}",
dist: "./dist/fonts/",
watch: "./src/fonts/**/*.{ttf,otf,woff,woff2}"
},
favicons: {
src: "./src/img/favicon.{jpg,jpeg,png,gif}",
dist: "./dist/img/favicons/",
},
server_config: {
src: "./src/.htaccess",
dist: "./dist/"
}
};
webpackConfig.mode = production ? "production" : "development";
webpackConfig.devtool = production ? false : "cheap-eval-source-map";
export const server = () => {
browsersync.init({
server: "./dist/",
port: 4000,
notify: true
});
gulp.watch(paths.views.watch, views);
gulp.watch(paths.styles.watch, styles);
gulp.watch(paths.scripts.watch, scripts);
gulp.watch(paths.images.watch, images);
gulp.watch(paths.webp.watch, webpimages);
};
export const cleanFiles = () => gulp.src("./dist/*", {read: false})
.pipe(clean())
.pipe(debug({
"title": "Cleaning..."
}));
export const serverConfig = () => gulp.src(paths.server_config.src)
.pipe(gulp.dest(paths.server_config.dist))
.pipe(debug({
"title": "Server config"
}));
export const smartGrid = cb => {
smartgrid("./src/styles/vendor", {
outputStyle: "scss",
filename: "_smart-grid",
columns: 12, // number of grid columns
offset: "30px", // gutter width
mobileFirst: true,
mixinNames: {
container: "container"
},
container: {
fields: "15px" // side fields
},
breakPoints: {
xs: {
width: "320px"
},
sm: {
width: "576px"
},
md: {
width: "768px"
},
lg: {
width: "992px"
},
xl: {
width: "1200px"
}
}
});
cb();
};
export const views = () => gulp.src(paths.views.src)
.pipe(pug({
plugins: [pugbem],
pretty: true
}))
.pipe(gulpif(production, replace("main.css", "main.min.css")))
.pipe(gulpif(production, replace("main.js", "main.min.js")))
.pipe(gulp.dest(paths.views.dist))
.on("end", browsersync.reload);
export const styles = () => gulp.src(paths.styles.src)
.pipe(gulpif(!production, sourcemaps.init()))
.pipe(plumber())
.pipe(sass())
.pipe(groupmediaqueries())
.pipe(gulpif(production, autoprefixer({
browsers: ["last 12 versions", "> 1%", "ie 8", "ie 7"]
})))
.pipe(gulpif(production, mincss({
compatibility: "ie8", level: {
1: {
specialComments: 0,
removeEmpty: true,
removeWhitespace: true
},
2: {
mergeMedia: true,
removeEmpty: true,
removeDuplicateFontRules: true,
removeDuplicateMediaBlocks: true,
removeDuplicateRules: true,
removeUnusedAtRules: false
}
}
})))
.pipe(gulpif(production, rename({
suffix: ".min"
})))
.pipe(plumber.stop())
.pipe(gulpif(!production, sourcemaps.write("./maps/")))
.pipe(gulp.dest(paths.styles.dist))
.pipe(debug({
"title": "CSS files"
}))
.pipe(browsersync.stream());
export const scripts = () => gulp.src(paths.scripts.src)
.pipe(webpackStream(webpackConfig), webpack)
.pipe(gulpif(production, rename({
suffix: ".min"
})))
.pipe(gulp.dest(paths.scripts.dist))
.pipe(debug({
"title": "JS files"
}))
.on("end", browsersync.reload);
export const images = () => gulp.src(paths.images.src)
.pipe(gulpif(production, imagemin([
imageminGiflossy({
optimizationLevel: 3,
optimize: 3,
lossy: 2
}),
imageminPngquant({
speed: 5,
quality: [0.3, 0.5]
}),
imageminZopfli({
more: true
}),
imageminMozjpeg({
progressive: true,
quality: 70
}),
imagemin.svgo({
plugins: [
{ removeViewBox: false },
{ removeUnusedNS: false },
{ removeUselessStrokeAndFill: false },
{ cleanupIDs: false },
{ removeComments: true },
{ removeEmptyAttrs: true },
{ removeEmptyText: true },
{ collapseGroups: true }
]
})
])))
.pipe(gulp.dest(paths.images.dist))
.pipe(debug({
"title": "Images"
}))
.on("end", browsersync.reload);
export const webpimages = () => gulp.src(paths.webp.src)
.pipe(webp(gulpif(production, imageminWebp({
lossless: true,
quality: 90,
alphaQuality: 90
}))))
.pipe(gulp.dest(paths.webp.dist))
.pipe(debug({
"title": "WebP images"
}));
export const fonts = () => gulp.src(paths.fonts.src)
.pipe(gulp.dest(paths.fonts.dist))
.pipe(debug({
"title": "Fonts"
}));
export const favs = () => gulp.src(paths.favicons.src)
.pipe(favicons({
icons: {
appleIcon: true,
favicons: true,
online: false,
appleStartup: false,
android: false,
firefox: false,
yandex: false,
windows: false,
coast: false
}
}))
.pipe(gulp.dest(paths.favicons.dist))
.pipe(debug({
"title": "Favicons"
}));
export const development = gulp.series(cleanFiles, smartGrid,
gulp.parallel(views, styles, scripts, images, webpimages, fonts, favs),
gulp.parallel(server));
export const prod = gulp.series(cleanFiles, smartGrid, serverConfig, views, styles, scripts, images, webpimages, fonts, favs);
export default development;