This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
138 lines (123 loc) · 2.97 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
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
import gulp from "gulp";
import del from "del";
import ghPages from "gulp-gh-pages";
import sass from "gulp-sass";
import postcss from "gulp-postcss";
import pxtorem from "postcss-pxtorem";
import autoprefixer from "autoprefixer";
import plumber from "gulp-plumber";
import browserSync from "browser-sync";
//browser-sync
const server = browserSync.create();
function reload(done) {
server.reload();
done();
}
function serve(done) {
server.init({
server: {
baseDir: "./dist"
}
});
done();
}
//Пути
const paths = {
styles: {
src: "src/styles/scss/main.scss",
watch: "src/styles/scss/**/*.scss",
dest: "dist/styles/"
},
stylesNlz: {
src: "node_modules/normalize.css/normalize.css",
dest: "dist/styles/found"
},
scripts: {
src: "src/scripts/main.js",
dest: "dist/scripts/"
},
html: {
src: "src/*.html",
dest: "dist/"
},
images: {
src: "src/images/**/*.*",
dest: "dist/images/"
},
fonts: {
src: "src/fonts/**/*.*",
dest: "dist/fonts/"
}
};
//Удаление папки dist
const clean = () => del(["dist"]);
//Стили
function styles() {
let plugins = [
autoprefixer({
browsers: ["last 10 version", "IE 11", "Firefox ESR"]
}),
pxtorem({
propList: ["*"],
selectorBlackList: [":root"],
minPixelValue: 7
})
];
return gulp
.src(paths.styles.src)
.pipe(plumber())
.pipe(sass())
.pipe(postcss(plugins))
.pipe(gulp.dest(paths.styles.dest));
}
//Перенос файлов
function stylesNlz() {
return gulp.src(paths.stylesNlz.src).pipe(gulp.dest(paths.stylesNlz.dest));
}
function html() {
return gulp
.src(paths.html.src)
.pipe(plumber())
.pipe(gulp.dest(paths.html.dest));
}
function images() {
return gulp.src(paths.images.src).pipe(gulp.dest(paths.images.dest));
}
function fonts() {
return gulp.src(paths.fonts.src).pipe(gulp.dest(paths.fonts.dest));
}
function scripts() {
return gulp
.src(paths.scripts.src)
.pipe(plumber())
.pipe(gulp.dest(paths.scripts.dest));
}
//Наблюдение за изменениями
function watch() {
gulp.watch(paths.html.src, gulp.series(html, reload));
gulp.watch(paths.fonts.src, gulp.series(fonts, reload));
gulp.watch(paths.styles.watch, gulp.series(styles, reload));
gulp.watch(paths.scripts.src, gulp.series(scripts, reload));
gulp.watch(paths.images.src, gulp.series(images, reload));
}
//Создание ветки gh-pages и загрузка туда содержимого папки dist
gulp.task("deploy", () => {
return gulp.src("./dist/**/*").pipe(ghPages());
});
//Запуск сборки
gulp.task(
"build",
gulp.series(
clean,
gulp.parallel(html, styles, scripts, stylesNlz, fonts, images)
)
);
//Запуск сборки, сервера и слежения за файлами
gulp.task(
"default",
gulp.series(
clean,
gulp.parallel(html, styles, stylesNlz, scripts, fonts, images),
gulp.parallel(serve, watch)
)
);