-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
157 lines (140 loc) · 3.49 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
// plugins for dev
import gulp from 'gulp';
import webpack from 'webpack-stream';
import fileinclude from 'gulp-file-include';
import { deleteAsync } from 'del';
import browserSync from 'browser-sync';
import notify from 'gulp-notify';
import plumber from 'gulp-plumber';
import newer from 'gulp-newer';
import rename from 'gulp-rename';
// compile scss
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass(dartSass);
// plugins for build
import htmlmin from 'gulp-htmlmin';
import groupCssMediaQueries from 'gulp-group-css-media-queries';
import cleanCss from 'gulp-clean-css';
import imagemin from 'gulp-imagemin';
import webpHtmlNoSvg from 'gulp-webp-html-nosvg';
// [email protected] is installed as well
import webpCss from 'gulp-webpcss';
import webp from 'gulp-webp';
const html = () => {
return gulp.src('src/*.html')
.pipe(plumber(notify.onError({
title: 'HTML',
message: '<%= error.message %>'
})))
.pipe(fileinclude())
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream())
}
const scss = () => {
return gulp.src('src/scss/**/*.scss', { sourcemaps: true })
.pipe(plumber(notify.onError({
title: 'HTML',
message: '<%= error.message %>'
})))
.pipe(sass())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist/css', { sourcemaps: true }))
.pipe(browserSync.stream())
}
const js = () => {
return gulp.src('src/js/app.js', { sourcemaps: true })
.pipe(plumber(notify.onError({
title: 'JS',
message: '<%= error.message %>'
})))
.pipe(webpack({
mode: 'development',
output: {
filename: 'app.min.js'
}
}))
.pipe(gulp.dest('dist/js', { sourcemaps: true }))
.pipe(browserSync.stream())
}
const images = () => {
return gulp.src('src/img/**/*')
.pipe(plumber(notify.onError({
title: 'IMAGES',
message: '<%= error.message %>'
})))
.pipe(newer('dist/img'))
.pipe(gulp.dest('dist/img'))
.pipe(browserSync.stream())
}
const fonts = () => {
return gulp.src('src/fonts/**/*')
.pipe(plumber(notify.onError({
title: 'FONTS',
message: '<%= error.message %>'
})))
.pipe(gulp.dest('dist/fonts'))
}
const reset = () => {
return deleteAsync('dist');
}
const server = () => {
browserSync.init({
server: {
baseDir: 'dist',
}
});
}
const watcher = () => {
gulp.watch('src/**/*.html', html);
gulp.watch('src/scss/**/*.scss', scss);
gulp.watch('src/js/**/*.js', js);
gulp.watch('src/img/**/*', images);
}
// build tasks
const buildHtml = () => {
return gulp.src('src/*.html')
.pipe(fileinclude())
.pipe(webpHtmlNoSvg())
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
}))
.pipe(gulp.dest('dist'))
}
const buildCss = () => {
return gulp.src('src/scss/**/*.scss')
.pipe(sass())
.pipe(webpCss())
.pipe(groupCssMediaQueries())
.pipe(rename({
suffix: '.min'
}))
.pipe(cleanCss())
.pipe(gulp.dest('dist/css'))
}
const buildJs = () => {
return gulp.src('src/js/app.js')
.pipe(webpack({
mode: 'production',
output: {
filename: 'app.min.js'
}
}))
.pipe(gulp.dest('dist/js'))
}
const buildImages = () => {
return gulp.src('src/img/**/*')
.pipe(webp())
.pipe(gulp.dest('dist/img'))
.pipe(gulp.src('src/img/**/*'))
.pipe(imagemin())
.pipe(gulp.dest('dist/img'))
}
const devTasks = gulp.parallel(html, scss, js, images, fonts);
const dev = gulp.series(reset, devTasks, gulp.parallel(watcher, server));
const buildTasks = gulp.parallel(buildHtml, buildCss, buildJs, buildImages, fonts);
const build = gulp.series(reset, buildTasks);
export { dev, build };