-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
141 lines (128 loc) · 3 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
const { src, dest, parallel, series, watch } = require('gulp');
const concat = require('gulp-concat');
const htmlMin = require('gulp-htmlmin');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify-es').default;
const babel = require('gulp-babel');
const notify = require('gulp-notify');
const sourcemaps = require('gulp-sourcemaps');
const del = require('del');
const rename = require('gulp-rename');
// DEV
const clean = () => {
return del(['dist/*'])
}
const fonts = () => {
return src([
'src/fonts/**/*.woff',
'src/fonts/**/*.woff2'
])
.pipe(dest('dist/fonts'))
}
const styles = () => {
return src('src/css/**/*.css')
.pipe(concat('style.css'))
.pipe(autoprefixer({
cascade: false,
grid: true,
flexbox: true,
}))
.pipe(dest('dist/css'))
.pipe(cleanCSS({
level: 2,
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(dest('dist/css'))
.pipe(browserSync.stream())
};
const resources = () => {
return src('src/resources/**')
.pipe(dest('dist'))
}
const html = () => {
return src('src/**/*.html')
.pipe(dest('dist'))
.pipe(browserSync.stream())
}
const scripts = () => {
return src([
'src/js/**/*.js',
])
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(concat('script.js'))
.pipe(uglify({
toplevel: true,
}).on('error', notify.onError()))
.pipe(rename({
suffix: '.min'
}))
.pipe(dest('dist/js'))
.pipe(browserSync.stream())
}
const watchFiles = () => {
browserSync.init({
server: {
baseDir: 'dist'
},
notify: false,
})
}
const images = () => {
return src([
'src/img/**/*.webp',
'src/img/**/*.svg'
])
.pipe(dest('dist/img'))
.pipe(browserSync.stream())
}
watch('src/**/*.html', html);
watch('src/css/**/*.css', styles);
watch('src/js/**/*.js', scripts);
watch('src/resources/**', resources);
watch([
'src/img/**/*.jpg',
'src/img/**/*.png',
'src/img/**/*.jpeg',
], images);
exports.clean = clean;
exports.fonts = fonts;
exports.styles = styles;
exports.html = html;
exports.scripts = scripts;
exports.images = images;
exports.default = series(clean, parallel(html, scripts, fonts, resources, images), styles, watchFiles);
// BUILD
const htmlBuild = () => {
return src('src/**/*.html')
.pipe(htmlMin({
collapseWhitespace: true
}))
.pipe(dest('dist'))
.pipe(browserSync.stream())
}
const stylesBuild = () => {
return src('src/css/**/*.css')
.pipe(sourcemaps.init())
.pipe(concat('style.css'))
.pipe(autoprefixer({
cascade: false,
grid: true,
flexbox: true,
}))
.pipe(cleanCSS({
level: 2,
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write())
.pipe(dest('dist/css'))
.pipe(browserSync.stream())
};
exports.build = series(clean, parallel(htmlBuild, scripts, fonts, resources, images), stylesBuild, watchFiles);