-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·143 lines (131 loc) · 3.26 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
"use strict";
const gulp = require("gulp");
const sass = require("gulp-sass");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("gulp-cssnano");
const gcmq = require("gulp-group-css-media-queries");
const del = require("del");
const htmlmin = require("gulp-htmlmin");
const imagemin = require("gulp-imagemin");
const svgstore = require("gulp-svgstore");
const plumber = require("gulp-plumber");
const rigger = require("gulp-rigger");
const stylelint = require("gulp-stylelint");
const babel = require("gulp-babel");
const uglify = require("gulp-uglify");
const concat = require("gulp-concat");
const rename = require("gulp-rename");
const browserSync = require("browser-sync").create();
gulp.task("html", () => {
return gulp
.src("./src/*.html")
.pipe(rigger())
.pipe(
htmlmin({
collapseWhitespace: true
})
)
.pipe(gulp.dest("./build"));
});
gulp.task("styles", () => {
return gulp
.src("./src/scss/styles.scss")
.pipe(plumber())
.pipe(
stylelint({
reporters: [{ formatter: "string", console: true }]
})
)
.pipe(sass())
.pipe(
postcss([
autoprefixer({
browsers: ["> 0.1%"],
cascade: false
})
])
)
.pipe(gcmq())
.pipe(gulp.dest("./build/css"))
.pipe(cssnano())
.pipe(rename("styles.min.css"))
.pipe(gulp.dest("./build/css"));
});
gulp.task("scripts", () => {
return gulp
.src("./src/js/**/*.js")
.pipe(plumber())
.pipe(
babel({
presets: ["@babel/env"]
})
)
.pipe(concat("scripts.js"))
.pipe(gulp.dest("./build/js"))
.pipe(uglify())
.pipe(rename("scripts.min.js"))
.pipe(gulp.dest("./build/js"));
});
gulp.task("svg-sprite", () => {
return gulp
.src("./src/img/sprite/**/*.svg")
.pipe(
svgstore({
inlineSvg: true
})
)
.pipe(rename("sprite.svg"))
.pipe(gulp.dest("./build/img"));
});
gulp.task("images", () => {
return gulp
.src([
"./src/img/**/*.{png,jpg,jpeg,svg,ico,gif,json,webmanifest,xml}",
"!./src/img/sprite/**/*.*"
])
.pipe(
imagemin([
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo({
plugins: [{ removeViewBox: false }, { cleanupIDs: false }]
})
])
)
.pipe(gulp.dest("./build/img"));
});
gulp.task("fonts", () => {
return gulp
.src("./src/fonts/**/*.{woff,woff2}")
.pipe(gulp.dest("./build/fonts"));
});
gulp.task('del-build', function() {
return del('build');
});
gulp.task("watch", () => {
gulp.watch("src/**/*.html", gulp.parallel("html"));
gulp.watch("src/scss/**/*.scss", gulp.parallel("styles"));
gulp.watch("src/js/**/*.js", gulp.parallel("scripts"));
});
gulp.task("serve", function() {
browserSync.init({
server: "./build",
notify: false,
open: true,
cors: true,
ui: false,
logPrefix: "DevServer",
host: "localhost",
port: 3000
});
browserSync.watch("build", browserSync.reload);
});
gulp.task(
"build",
gulp.series("del-build", gulp.parallel("images", "html", "styles", "scripts", "svg-sprite", "fonts"))
);
gulp.task(
"start",
gulp.series("build", gulp.parallel("serve", "watch"))
);