-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
112 lines (98 loc) · 2.88 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
// Import modules
import gulp from 'gulp';
import cssMin from 'gulp-clean-css';
import concat from 'gulp-concat';
import imageMin from 'gulp-imagemin';
import webp from 'gulp-webp';
import merge from 'merge-stream';
import plumber from 'gulp-plumber';
import nodeSass from 'node-sass';
import gulpSass from 'gulp-sass';
import uglify from 'gulp-uglify-es';
import purgeCss from 'gulp-purgecss';
const sass = gulpSass(nodeSass);
// Required directories
const dir = {
src: 'src',
build: 'build',
nm: 'node_modules/',
};
const path = {
build: {
js: `${dir.build}/js/`,
css: `${dir.build}/css/`,
images: `${dir.build}/img/`,
fonts: `${dir.build}/fonts/`,
html: `${dir.build}`,
},
src: {
html: `${dir.src}/**/*.html`,
js: [
`${dir.nm}/jquery/dist/jquery.min.js`,
`${dir.nm}/bootstrap/dist/js/bootstrap.bundle.js`,
`${dir.nm}/vanilla-lazyload/dist/lazyload.min.js`,
`${dir.src}/js/helper.js`,
],
scss: [
`${dir.nm}/bootstrap/scss/bootstrap.scss`,
`${dir.src}/css/app.scss`,
],
css: [
`${dir.src}/css/additional.css`,
],
img: `${dir.src}/img/**/*.*`,
fontAwesome: 'node_modules/@fortawesome/fontawesome-free/webfonts/*.*',
},
watch: {
html: `${dir.src}/**/*.html`,
js: `${dir.src}/js/**/*.js`,
styles: `${dir.src}/css/**/*.scss`,
images: `${dir.src}/img/**/*.*`,
},
clean: `${dir.build}`, // path to clear production build
};
export const buildFonts = () => gulp.src(path.src.fontAwesome)
.pipe(gulp.dest(path.build.fonts));
export const buildPages = () => gulp.src(path.src.html)
.pipe(gulp.dest(path.build.html));
export const buildImages = () => gulp.src(path.src.img, { since: gulp.lastRun(buildImages) })
.pipe(imageMin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
interlaced: true,
}))
.pipe(webp())
.pipe(gulp.dest(path.build.images));
export const buildScripts = () => gulp.src(path.src.js)
.pipe(plumber())
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(plumber.stop())
.pipe(gulp.dest(path.build.js));
export const buildStyles = () => {
const scssFiles = gulp.src(path.src.scss)
.pipe(sass())
.pipe(concat('styles.scss'));
const cssFiles = gulp.src(path.src.css)
.pipe(concat('styles.css'));
return merge(scssFiles, cssFiles)
.pipe(concat('styles.css'))
.pipe(plumber())
.pipe(cssMin())
.pipe(plumber.stop())
.pipe(purgeCss({
content: [path.src.html],
}))
.pipe(gulp.dest(path.build.css));
};
export const devWatch = () => {
gulp.watch(path.watch.html, buildPages);
gulp.watch(path.watch.styles, buildStyles);
gulp.watch(path.watch.images, buildImages);
gulp.watch(path.watch.js, buildScripts);
};
export const build = gulp.series(
gulp.parallel(buildPages, buildStyles, buildScripts, buildImages, buildFonts),
);
export const dev = gulp.parallel(build, devWatch);
export default dev;