-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (86 loc) · 2.61 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
var gulp = require('gulp'),
minifyCSS = require('gulp-minify-css'),
uglify = require('gulp-uglify')
del = require('del')
rename = require('gulp-rename'),
esLint = require('gulp-eslint'),
plumber = require('gulp-plumber'),
babel = require('gulp-babel')
liveReload = require('gulp-livereload')
autoprefixer = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
notify = require('gulp-notify');
gulp.task('delete', function() {
del(['build/*'], function(err) {
if (err) {
console.error(err);
} else {
console.log('Files deleted');
}
});
});
gulp.task('style', function() {
return gulp
.src('css/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(minifyCSS())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('build'))
.pipe(liveReload());
});
gulp.task('lint', function () {
return gulp
.src(['js/**/*.js'])
.pipe(plumber())
.pipe(esLint())
.pipe(esLint.format())
.pipe(esLint.failOnError());
});
gulp.task('script', function() {
return gulp
.src('js/*.js')
.pipe(plumber())
.pipe(babel())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('build'))
.pipe(liveReload());
});
gulp.task('php', function() {
return gulp
.src('*.php')
.pipe(liveReload());
});
gulp.task('image', function() {
return gulp.src('img/*')
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('build/img'))
.pipe(notify({ message: 'Images task complete' }));
});
gulp.task('watch', function() {
liveReload.listen();
gulp.watch('css/**/*.scss', ['style']);
gulp.watch('js/**/*.js', ['lint', 'script']);
gulp.watch('**/*.php', ['php']);
gulp.watch('img/**/*', ['php']);
});
gulp.task('default', ['delete', 'style', 'lint', 'script', 'image', 'watch']);