-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (85 loc) · 3.05 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
const gulp = require('gulp'),
browserSync = require('browser-sync').create(),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default,
cleancss = require('gulp-clean-css'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
newer = require('gulp-newer'),
responsive = require('gulp-responsive'),
del = require('del'),
babel = require('gulp-babel');
// Локальный сервер
gulp.task('browser-sync', function () {
browserSync.init({
server: {
baseDir: 'dist',
browser: 'chrome'
},
notify: false,
online: true, // Для работы офлайн
// tunnel: true, tunnel: 'projectname', // Страница тунеля: http://projectname.localtunnel.me
})
});
function bsReload(done) { browserSync.reload(); done() };
// Пользовательские стили
gulp.task('styles', function () {
return gulp.src('app/css/**/*.css')
.pipe(concat('styles.min.css'))
.pipe(autoprefixer({
// grid: true, //Гриды в IE
overrideBrowserslist: ['last 10 versions']
}))
.pipe(cleancss({ level: { 1: { specialComments: 0 } } }))
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.stream())
});
// Скрипты и бибилиотеки
gulp.task('scripts', function () {
return gulp.src([
'app/js/_libs.js', // Библиотеки
'app/js/_custom.js', // Пользовательские стили
])
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(concat('scripts.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.reload({ stream: true }))
});
var quality = 95; // Качество изображения
gulp.task('img-responsive-1x', async function () {
return gulp.src('app/img/_src/**/*.{png,jpg,jpeg,webp,raw}')
.pipe(newer('app/img/@1x'))
.pipe(responsive({
'**/*': { width: '50%', quality: quality }
})).on('error', function (e) { console.log(e) })
.pipe(rename(function (path) { path.extname = path.extname.replace('jpeg', 'jpg') }))
.pipe(gulp.dest('dist/img/@1x'))
});
gulp.task('img-responsive-2x', async function () {
return gulp.src('app/img/_src/**/*.{png,jpg,jpeg,webp,raw}')
.pipe(newer('app/img/@2x'))
.pipe(responsive({
'**/*': { width: '100%', quality: quality }
})).on('error', function (e) { console.log(e) })
.pipe(rename(function (path) { path.extname = path.extname.replace('jpeg', 'jpg') }))
.pipe(gulp.dest('dist/img/@2x'))
});
gulp.task('img', gulp.series('img-responsive-1x', 'img-responsive-2x', bsReload));
gulp.task('cleanimg', function () {
return del(['app/img/@*'], { force: true })
});
gulp.task('code', function () {
return gulp.src('app/**/*.html')
.pipe(gulp.dest('dist/'))
.pipe(browserSync.reload({ stream: true }))
});
gulp.task('watch', function () {
gulp.watch('app/css/**/*.css', gulp.parallel('styles'));
gulp.watch(['app/js/_custom.js', 'app/js/_libs.js'], gulp.parallel('scripts'));
gulp.watch('app/*.html', gulp.parallel('code'));
gulp.watch('app/img/_src/**/*', gulp.parallel('img'));
});
gulp.task('default', gulp.parallel('img', 'styles', 'scripts', 'browser-sync', 'watch'));