-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (80 loc) · 2.65 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
'use strict';
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
sass = require('gulp-sass'),
cleanCss = require('gulp-clean-css'),
fileinclude = require('gulp-file-include'),
browserSync = require('browser-sync').create(),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
autoprefixer = require('gulp-autoprefixer'),
cache = require('gulp-cache'),
clean = require('gulp-clean');
//Scripts
gulp.task('js', function () {
gulp.src('src/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('build/js'))
});
//Styles
gulp.src('src/sass/bundle.scss')
.pipe(sass())
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(cleanCss())
.pipe(concat('style.min.css'))
.pipe(gulp.dest('build/css'))
.pipe(browserSync.reload({stream: true}))
gulp.task('sass', function () {
});
//Html include
gulp.task('html', function() {
return gulp.src(['src/pages/*.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file',
indent: true
}))
.pipe(gulp.dest('build'))
});
//Fonts
gulp.task('fonts', function () {
gulp.src('src/assets/fonts/**/*')
.pipe(gulp.dest('build/fonts'))
});
//Images compression
gulp.task('img', function() {
return gulp.src('src/assets/img/**/*')
.pipe(cache(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
})))
.pipe(gulp.dest('build/img'));
});
//Clean build
gulp.task('clean', function () {
return gulp.src('build/', {read: false})
.pipe(clean()); //TODO doesn't remove css folder
});
//Clear cache
gulp.task('clear', function () {
return cache.clearAll();
});
//BrowserSync
gulp.task('browser-sync', function() {
browserSync.init({
server: { // Определяем параметры сервера
baseDir: 'build/' // Директория для сервера - app
},
notify: false // Отключаем уведомления
});
});
// Watch
gulp.task('watch', ['html', 'sass', 'js', 'img', 'fonts'], function() {
gulp.watch('src/components/**/*.scss', ['sass']).on('change', browserSync.reload);
gulp.watch('src/components/**/*.html', ['html']).on('change', browserSync.reload);
gulp.watch('src/js/**/*.js', ['js']).on('change', browserSync.reload);
});
gulp.task('default', ['watch', 'browser-sync']);