-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
192 lines (173 loc) · 5.29 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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 autoprefixer = require(`autoprefixer`);
const server = require(`browser-sync`).create();
const csso = require(`gulp-csso`);
const rename = require(`gulp-rename`);
const imagemin = require(`gulp-imagemin`);
const webp = require(`gulp-webp`);
const svgstore = require(`gulp-svgstore`);
const del = require(`del`);
const uglify = require(`gulp-uglify`);
const webpackStream = require(`webpack-stream`);
const webpackConfig = require(`./webpack.config.js`);
const concat = require(`gulp-concat`);
const fileinclude = require(`gulp-file-include`);
gulp.task(`html`, function () {
return gulp.src([`source/html/*.html`])
.pipe(fileinclude({
prefix: `@@`,
basepath: `@root`,
context: { // глобальные переменные для include
test: `text`,
headerActiveLinkIndex: null,
headerListFirstLinks: [
{
"text": "Услуги",
"href": "services.html",
"index": 0
},
{
"text": "Портфолио",
"href": "portfolio.html",
"index": 1
}
],
headerListSecondLinks: [
{
"text": "О нас",
"href": "about-us.html",
"index": 2
},
{
"text": "Блог",
"href": "blog.html",
"index": 3
},
{
"text": "Контакты",
"href": "contacts.html",
"index": 4
}
]
}
}))
.pipe(gulp.dest(`build`));
});
gulp.task(`css`, function () {
return gulp.src(`source/sass/style.scss`)
.pipe(plumber())
.pipe(sourcemap.init())
.pipe(sass())
.pipe(postcss([autoprefixer({
grid: true,
})]))
.pipe(gulp.dest(`build/css`))
.pipe(csso())
.pipe(rename(`style.min.css`))
.pipe(sourcemap.write(`.`))
.pipe(gulp.dest(`build/css`))
.pipe(server.stream());
});
gulp.task(`script`, function () {
return gulp.src([`source/js/main.js`])
.pipe(webpackStream(webpackConfig))
.pipe(uglify())
.pipe(gulp.dest(`build/js`));
});
gulp.task(`svgo`, function () {
return gulp.src(`source/img/**/*.{svg}`)
.pipe(imagemin([
imagemin.svgo({
plugins: [
{removeViewBox: false},
{removeRasterImages: true},
{removeUselessStrokeAndFill: false},
]
}),
]))
.pipe(gulp.dest(`source/img`));
});
gulp.task(`sprite`, function () {
return gulp.src(`source/img/sprite/*.svg`)
.pipe(svgstore({inlineSvg: true}))
.pipe(rename(`sprite_auto.svg`))
.pipe(gulp.dest(`build/img`));
});
gulp.task(`server`, function () {
server.init({
server: `build/`,
notify: false,
open: true,
cors: true,
ui: false,
});
gulp.watch(`source/html/**/*.html`, gulp.series(`html`, `refresh`));
gulp.watch(`source/sass/**/*.{scss,sass}`, gulp.series(`css`));
gulp.watch(`source/js/**/*.js`, gulp.series(`script`, `refresh`));
gulp.watch(`source/img/**/*.svg`, gulp.series(`copysvg`, `sprite`, `html`, `refresh`));
gulp.watch(`source/img/**/*.{png,jpg}`, gulp.series(`copypngjpg`, `html`, `refresh`));
});
gulp.task(`refresh`, function (done) {
server.reload();
done();
});
gulp.task(`copysvg`, function () {
return gulp.src(`source/img/**/*.svg`, {base: `source`})
.pipe(gulp.dest(`build`));
});
gulp.task(`copypngjpg`, function () {
return gulp.src(`source/img/**/*.{png,jpg}`, {base: `source`})
.pipe(gulp.dest(`build`));
});
gulp.task(`copy`, function () {
return gulp.src([
`source/fonts/**/*.{woff,woff2}`,
`source/favicon/**`,
`source/img/**`,
`source/*.php`,
`source/video/**`, // учтите, что иногда git искажает видеофайлы, pdf и gif - проверяйте и если обнаруживаете баги - скидывайте тестировщику такие файлы напрямую
`source/downloads/**`,
], {
base: `source`,
})
.pipe(gulp.dest(`build`));
});
gulp.task(`clean`, function () {
return del(`build`);
});
gulp.task(`build`, gulp.series(
`clean`,
`svgo`,
`copy`,
`sprite`,
`css`,
`script`,
`html`
));
gulp.task(`start`, gulp.series(`build`, `server`));
// Optional tasks
//---------------------------------
// Вызывайте через `npm run taskName`
gulp.task(`webp`, function () {
return gulp.src(`source/img/**/*.{png,jpg}`)
.pipe(webp({quality: 90}))
.pipe(gulp.dest(`source/img`));
});
gulp.task(`imagemin`, function () {
return gulp.src(`build/img/**/*.{png,jpg}`)
.pipe(imagemin([
imagemin.optipng({optimizationLevel: 3}),
imagemin.mozjpeg({quality: 75, progressive: true}),
]))
.pipe(gulp.dest(`build/img`));
});
// для отправки заказчику неминифицированного js "для чтения"
gulp.task(`concat-js`, function () {
return gulp.src([`source/js/main.js`, `source/js/utils/**/*.js`, `source/js/modules/**/*.js`])
.pipe(concat(`main.readonly.js`))
.pipe(gulp.dest(`build/js`));
});