-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
104 lines (91 loc) · 2.37 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
import gulp from "gulp";
import browserSync from "browser-sync";
import * as dartSass from "sass";
import gulpSass from "gulp-sass";
const sass = gulpSass(dartSass);
import postcss from "gulp-postcss";
import cssnano from "cssnano";
import autoPrefixer from "gulp-autoprefixer";
import rename from "gulp-rename";
import { deleteAsync } from "del";
const path = {
build: {
css: "assets/css/",
},
src: {
html: "*.html",
scss: `assets/scss/**/*.scss`,
js: "assets/js/app.js",
fonts: "assets/fonts/*.*",
img: "assets/img/*.*",
},
watch: {
html: "*.html",
css: "assets/css/*.css",
scss: `assets/scss/**/*.scss`,
js: "assets/js/**/*.js",
fonts: "assets/fonts/**/*.*",
img: "assets/img/**/*.*",
},
};
// Tasks
//Reset
const reset = () => {
return deleteAsync(["assets/css/"]);
};
// Compile SCSS
const scss = () => {
return gulp
.src(path.src.scss, { sourcemaps: true })
.pipe(
sass({
outputStyle: "expanded",
}).on("error", sass.logError),
)
.pipe(
autoPrefixer({
grid: true,
}),
)
.pipe(postcss([cssnano()]))
.pipe(rename({ extname: ".min.css" }))
.pipe(gulp.dest(path.build.css))
.pipe(browserSync.stream());
};
// Local Server
const server = (done) => {
browserSync.init({
server: { baseDir: "./" },
port: 3000,
notify: false, // Отключаем уведомления
open: true, // Автоматически открывать браузер
cors: true,
ui: false,
});
done();
};
// Reload Server
const reload = (done) => {
browserSync.reload();
done();
};
// Watcher
const watcher = () => {
// Watch SCSS
gulp.watch(path.watch.scss, scss);
// Watch HTML and reload on changes
gulp.watch(path.watch.html).on("change", browserSync.reload);
// Watch CSS and reload on changes
gulp.watch(path.watch.css).on("change", browserSync.reload);
// Watch JS and reload on changes
gulp.watch(path.watch.js).on("change", browserSync.reload);
// Watch fonts and reload on changes
gulp.watch(path.watch.fonts).on("change", browserSync.reload);
// Watch images and reload on changes
gulp.watch(path.watch.img).on("change", browserSync.reload);
};
// Main Tasks
const dev = gulp.series(reset, scss, gulp.parallel(watcher, server));
const build = gulp.series(reset, scss);
gulp.task("default", dev);
gulp.task("build", build);