-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
142 lines (129 loc) · 3.41 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
const gulp = require("gulp");
const plumber = require("gulp-plumber");
const sourcemap = require("gulp-sourcemaps");
const sass = require("gulp-sass");
const postcss = require("gulp-postcss");
const csso = require("gulp-csso"); //минификация стилей
const autoprefixer = require("autoprefixer");
const sync = require("browser-sync").create();
const htmlmin = require('gulp-htmlmin'); //минификация html
const fileinclude = require('gulp-file-include');
const rename = require("gulp-rename");
const webp = require("gulp-webp");
const imagemin = require("gulp-imagemin");
const svgstore = require("gulp-svgstore");
const del = require("del");
const terser = require("gulp-terser"); //обратка и минифик файлов js
//svg sprite
const sprite = () => {
return gulp.src("source/img/**/*.svg")
.pipe(imagemin([
imagemin.svgo()
]))
.pipe(svgstore())
.pipe(rename("sprite.svg"))
.pipe(gulp.dest("docs/img"))
};
exports.sprite = sprite;
//webp
const makewebp = () => {
return gulp.src("source/img/**/*.{jpg,png,svg}")
.pipe(webp({ quality: 70 }))
.pipe(gulp.dest('source/img'));
};
exports.makewebp = makewebp;
//images
const images = () => {
return gulp.src("source/img/**/*.{jpg,png,svg}") //** - смотрит в любую вложенность
.pipe(imagemin([
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.mozjpeg({ progressive: true }),
imagemin.svgo()
]))
.pipe(gulp.dest('source/img'))
};
exports.images = images;
// Styles
const styles = () => {
return gulp.src("source/sass/style.scss")
.pipe(plumber())
.pipe(sourcemap.init())
.pipe(sass())
.pipe(postcss([
autoprefixer()
]))
.pipe(gulp.dest("docs/css"))
.pipe(csso())
.pipe(rename('style.min.css'))
.pipe(sourcemap.write(".")) //положил файл с картами кодами в корневую папку
.pipe(gulp.dest("docs/css")) //галп положи файлы в папку.
.pipe(sync.stream());
};
exports.styles = styles;
// Html
const html = () => {
return gulp.src("source/*.html")
.pipe(fileinclude())
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('docs'));
};
exports.html = html;
//javascript
const scripts = () => {
return gulp.src('source/js/script.js')
.pipe(gulp.dest('docs/js'))
.pipe(terser())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('docs/js'))
.pipe(sync.stream());
}
exports.scripts = scripts;
//copy
const copy = () => {
return gulp.src([
"source/fonts/**/*.{woff,woff2}",
"source/*.ico",
"source/img/**",
], {
base: "source"
})
.pipe(gulp.dest("docs"));
};
exports.copy = copy;
//clean
const clean = () => {
return del("docs");
};
exports.clean = clean;
// Server
const server = (done) => {
sync.init({
server: {
baseDir: 'docs/'
},
cors: true,
notify: false,
ui: false,
});
done();
}
exports.server = server;
//build
const build = gulp.series(
clean,
gulp.parallel(html, styles, scripts, sprite), gulp.series(copy));
exports.build = build;
// Watcher
const watcher = () => {
gulp.watch("source/js/**/*.js", gulp.series("scripts"));
gulp.watch("source/sass/**/*.scss", gulp.series("styles"));
gulp.watch("source/*.html", gulp.series("html")).on("change", sync.reload);
}
exports.default = gulp.series(
build, server, watcher
);