-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
198 lines (177 loc) · 5.86 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
193
194
195
196
197
198
// import path from 'node:path';
const path = require('node:path');
const gulp = require('gulp'); // Подключаем Gulp
const browserSync = require('browser-sync').create();
const watch = require('gulp-watch');
const dartsass = require('sass');
const gulpsass = require('gulp-sass');
const qcmq = require('gulp-group-css-media-queries');
const smartgrid = require('smart-grid');
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const notify = require('gulp-notify');
const cssnano = require('gulp-cssnano');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const plumber = require('gulp-plumber');
const fileinclude = require('gulp-file-include'); // Для подключения файлов друг в друга
const del = require('del');
const beautify = require('gulp-beautify');
const sass = gulpsass(dartsass);
const styleLibCollection = ['node_modules/normalize.css/normalize.css', 'node_modules/animate.css/animate.css'];
// Таск для компиляции SCSS в CSS
gulp.task('scss', function (callback) {
return (
gulp
.src('src/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(
plumber({
errorHandler: notify.onError(function (err) {
return {
title: 'Styles',
sound: false,
message: err.message,
};
}),
}),
)
.pipe(sass())
.pipe(
autoprefixer({
overrideBrowserslist: ['last 4 versions'],
}),
)
.pipe(qcmq()) //группировка медиа запросов
// .pipe(cssnano()) //минификация css
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./maps/'))
.pipe(gulp.dest('./build/css/'))
.pipe(browserSync.stream())
);
callback();
});
// настройки сетки smart-grid
gulp.task('smart-grid', (cb) => {
smartgrid('src/scss/stylesheets/', {
outputStyle: 'scss',
filename: '_smart-grid',
columns: 12, // number of grid columns
offset: '1.25rem', // gutter width - 20px
mobileFirst: false,
mixinNames: {
container: 'container',
},
container: {
maxWidth: '1320px',
fields: '0.9375rem', // side fields - 15px
},
breakPoints: {
xs: {
width: '20rem', // 320px
},
sm: {
width: '36rem', // 576px
},
md: {
width: '48rem', // 768px
},
lg: {
width: '62rem', // 992px
},
xl: {
width: '75rem', // 1200px
},
},
});
cb();
});
// Таск для сборки HTML и шаблонов
gulp.task('html', function (callback) {
return gulp
.src('./src/html/*.html')
.pipe(
plumber({
errorHandler: notify.onError(function (err) {
return {
title: 'HTML include',
sound: false,
message: err.message,
};
}),
}),
)
.pipe(
fileinclude({
prefix: '@@',
basepath: path.resolve(__dirname, './src/html/'),
}),
)
.pipe(
beautify.html({
indent_size: 2,
preserve_newlines: false,
}),
)
.pipe(gulp.dest('./build/'))
.pipe(browserSync.reload({ stream: true }));
callback();
});
// объединям все css библиотеки в одну
gulp.task('css-lib', function () {
return gulp
.src(styleLibCollection)
.pipe(concat('libs.css'))
.pipe(cssnano()) // минификация
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./build/css/libs'))
.pipe(browserSync.reload({ stream: true }));
});
// Копирование Изображений
gulp.task('copy:img', function (callback) {
return gulp.src('./src/img/**/*.*').pipe(gulp.dest('./build/img/'));
callback();
});
// Копирование шрифтов
gulp.task('copy:fonts', function (callback) {
return gulp.src('./src/fonts/**/*.*').pipe(gulp.dest('./build/fonts/'));
callback();
});
// Копирование Скриптов
gulp.task('copy:js', function (callback) {
return gulp.src(['./src/js/**/*.*']).pipe(gulp.dest('./build/js/'));
callback();
});
// Слежение за HTML и CSS и обновление браузера
gulp.task('watch', function () {
watch('./src/html/data/*.json', gulp.parallel('html')).on('change', browserSync.reload);
// Слежение за HTML и обновление браузера
watch(['./src/*.html'], gulp.parallel(browserSync.reload));
// Следим за картинками и скриптами и обновляем браузер
watch(['./build/js/**/*.*', './build/img/**/*.*', './build/fonts/**/*.*'], gulp.parallel(browserSync.reload));
// Запуск слежения и компиляции SCSS с задержкой
watch('./src/scss/**/*.scss', function () {
setTimeout(gulp.parallel('scss'), 500);
});
// Слежение за HTML и сборка страниц и шаблонов
watch('./src/html/**/*.html', gulp.parallel('html'));
// Следим за картинками и скриптами, и копируем их в build
watch('./src/img/**/*.*', gulp.parallel('copy:img'));
watch('./src/fonts/**/*.*', gulp.parallel('copy:fonts'));
watch('./src/js/**/*.*', gulp.parallel('copy:js'));
});
// Задача для старта сервера из папки app
gulp.task('server', function () {
browserSync.init({
server: {
baseDir: './build/',
},
notify: false,
});
});
gulp.task('clean:build', function () {
return del('./build');
});
// Дефолтный таск (задача по умолчанию)
// Запускаем одновременно задачи server и watch
gulp.task('default', gulp.series(gulp.parallel('clean:build'), gulp.parallel('html', 'scss', 'css-lib', 'copy:img', 'copy:fonts', 'copy:js'), gulp.parallel('server', 'watch')));