-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (72 loc) · 1.79 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
/**
* Compile .scss source to .css
*/
var gulp = require('gulp');
var sass = require('gulp-sass');
var stripCssComments = require('gulp-strip-css-comments');
var prefix = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var imagemin = require('gulp-imagemin');
var debug = require('gulp-debug');
var cssbeautify = require('gulp-cssbeautify');
/**
* Error handler function so we can see when errors happen.
* @param {object} err error that was thrown
* @returns {undefined}
*/
function handleError(err) {
// eslint-disable-next-line no-console
console.error(err.toString());
this.emit('end');
}
// Variables for folder path.
var paths = {
styles: {
source: 'scss/**/*.scss',
destination: 'dist/css/'
},
images: {
source: 'images/**/*.{JPG,jpg,png,gif,svg}',
destination: 'dist/images/'
}
};
// Compile SASS.
gulp.task('build:css', async function () {
return gulp.src(paths.styles.source)
.pipe(sass({ outputStyle: 'expanded' }).on('error', handleError))
.pipe(debug({ title: 'Styles update 👉' }))
.pipe(
prefix({
cascade: false
})
)
.pipe(stripCssComments())
.pipe(
rename(function (path) {
path.dirname = '';
return path;
})
)
.pipe(cssbeautify({
indent: ' ',
autosemicolon: true
}))
.pipe(gulp.dest(paths.styles.destination));
});
// Image optimization.
gulp.task('images', function () {
return gulp.src(paths.images.source)
.pipe(debug({ title: 'Optimized 👉' }))
.pipe(imagemin())
.pipe(
rename(function (path) {
path.dirname = '';
return path;
})
)
.pipe(gulp.dest(paths.images.destination));
});
// Watch
gulp.task('watch', function () {
gulp.watch(paths.styles.source, {}, gulp.series('build:css'));
});