-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
108 lines (93 loc) · 3.07 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
browsersync = require('browser-sync').create(),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cleancss = require('gulp-clean-css'),
rename = require('gulp-rename'),
notify = require('gulp-notify'),
cssbeautify = require('gulp-cssbeautify')
del = require('del'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer');
gulp.task('browser-sync', function() {
browsersync.init({
server: {
baseDir: 'src'
},
notify: false
});
});
gulp.task('clean', function() {
return del.sync('dist'); // Удаляем папку dist перед сборкой
});
gulp.task('img', function() {
return gulp.src('src/img/**/*')
.pipe(cache(imagemin({ // С кешированием
// .pipe(imagemin({ // Сжимаем изображения без кеширования
interlaced: true,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))/**/)
.pipe(gulp.dest('dist/img'));
});
let autoprefixBrowsers = ['> 1%', 'last 2 versions', 'firefox >= 4', 'safari 7', 'safari 8', 'IE 10', 'IE 11'];
gulp.task('sass', function(){
return gulp.src('src/sass/**/*.sass')
.pipe(sass({ outputStyle: 'expand' }).on('error', notify.onError()))
.pipe(cssbeautify({
indent: ' ',
openbrace: 'end-of-line',
autosemicolon: true
}))
.pipe(rename({basename: "style"})).pipe(gulp.dest('src/css'))
.pipe(rename({
suffix: ".min",
prefix: ""
}))
.pipe(autoprefixer({browsers: autoprefixBrowsers }))
.pipe(cleancss({level: { 1: { specialComments: 0 } } }))
.pipe(gulp.dest('src/css'))
.pipe(browsersync.reload({stream: true}))
.on('error', gutil.log)
});
gulp.task('js', function() {
return gulp.src([
'src/libs/jquery/dist/jquery.min.js',
'src/libs/jquery.easing/js/jquery.easing.min.js',
'src/libs/skitter-slideshow/dist/jquery.skitter.min.js',
'src/libs/magnific-popup/dist/jquery.magnific-popup.min.js',
'src/libs/owl.carousel/dist/owl.carousel.min.js',
'src/js/common.js', // Always at the end
])
.pipe(concat('scripts.min.js'))
// .pipe(uglify()) // Mifify js (opt.)
.pipe(gulp.dest('src/js'))
.pipe(browsersync.reload({ stream: true }))
});
gulp.task('watch',['sass','js','browser-sync'], function() {
gulp.watch('src/sass/**/*.sass',['sass']);
gulp.watch(['libs/**/*.js', 'src/js/common.js'], ['js']);
gulp.watch('src/*.html', browsersync.reload)
});
gulp.task('clear', function (callback) {
return cache.clearAll();
})
gulp.task('build', ['clean', 'img', 'sass', 'js'], function() {
var buildCss = gulp.src([
'src/css/*.css',
'src/css/*.min.css'
])
.pipe(gulp.dest('dist/css'))
var buildFonts = gulp.src('src/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
var buildJs = gulp.src('src/js/**/*')
.pipe(gulp.dest('dist/js'))
var buildHtml = gulp.src('src/*.html')
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['watch']);