-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
137 lines (126 loc) · 3.64 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
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const rev = require('gulp-rev');
const minify = require('gulp-minify');
const notify = require('gulp-notify');
const imagemin = require('gulp-imagemin');
const plumber = require('gulp-plumber');
const sizereport = require('gulp-sizereport');
const del = require('del');
// ------------------
// Gulp Tasks
// ------------------
gulp.task('sass', () => {
return (
gulp
.src('./Resources/Assets/**/*.scss')
//.pipe(sourcemaps.init())
.pipe(
plumber({
errorHandler: notify.onError({
title: 'Error CSS',
message: '<%= error.message %>',
sound: 'Frog'
})
})
)
.pipe(
sass({
outputStyle: 'expanded',
sourceMap: true,
errLogToConsole: true
}).on('error', sass.logError)
)
.pipe(
autoprefixer({
overrideBrowserslist: ['last 2 versions and > 0.5%'],
cascade: false
})
)
.pipe(
cleanCSS({
level: 2
})
)
//.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist'))
);
});
gulp.task('js', () => {
return gulp
.src('./Resources/Assets/**/*.js')
.pipe(
minify({
ext: {
src: '-debug.js',
min: '.js'
}
})
)
.pipe(gulp.dest('./dist'));
});
gulp.task('img', () => {
return gulp
.src('./Resources/Assets/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(
imagemin(
[
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [
{ removeViewBox: true },
{ cleanupIDs: false }
]
})
],
{ verbose: true }
)
)
.pipe(gulp.dest('./dist'));
});
gulp.task('clean', done => {
del.sync('./dist', {
force: true
});
done();
});
gulp.task('clean_watch', done => {
del.sync(['./dist/**/js', './dist/**/scss'], {
force: true
});
done();
});
gulp.task('rev', () => {
return gulp
.src('./dist/**/*.+(css|js)')
.pipe(rev())
.pipe(gulp.dest('./dist')) // write rev'd assets to build dir
.pipe(rev.manifest())
.pipe(gulp.dest('./dist')); // write manifest to build dir
});
gulp.task('size', () => {
return gulp.src('./dist/**/*.+(css|js)').pipe(
sizereport({
gzip: true
})
);
});
// Main tasks
gulp.task(
'build',
gulp.series('clean', gulp.parallel('img', 'js', 'sass'), 'rev', 'size')
);
gulp.task(
'build_watch',
gulp.series('clean_watch', gulp.parallel('js', 'sass'), 'rev', 'size')
);
gulp.task('watch', () => {
console.log('WATCH INCLUDE (css) ' + './Resources/Assets/**/*.scss');
console.log('WATCH INCLUDE (js) ' + './Resources/Assets/**/*.js');
gulp.watch(['./Resources/Assets/**/*.scss', './Resources/Assets/**/*.js'], { interval: 1000, usePolling: true }, gulp.series('build_watch'));
});