-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
77 lines (77 loc) · 2.02 KB
/
gulpfile.babel.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
const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const useref = require('gulp-useref');
const uglify = require('gulp-uglify');
const gulpIf = require('gulp-if');
const cssnano = require('gulp-cssnano');
const imagemin = require('gulp-imagemin');
const cache = require('gulp-cache');
const del = require('del');
const runSequence = require('run-sequence');
// Build asset pipeline
gulp.task('build', (callback) => {
runSequence('clean:dist',
['sass', 'useref', 'images', 'fonts'],
callback,
);
});
// Dev pipeline
gulp.task('default', (callback) => {
runSequence(['sass', 'browserSync', 'watch'],
callback,
);
});
// Sass compilation
gulp.task('sass', () => {
gulp.src('public/assets/scss/styles.scss')
.pipe(sass())
.pipe(gulp.dest('public/assets/css'))
.pipe(browserSync.reload({
stream: true,
}));
});
// Browser sync
gulp.task('browserSync', () => {
browserSync.init({
server: {
baseDir: 'public',
},
});
});
// File minification
gulp.task('useref', () => {
gulp.src('public/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify({ mangle: false })))
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'));
});
// Image optimisation
gulp.task('images', () => {
gulp.src('public/assets/images/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true,
})))
.pipe(gulp.dest('dist/images'));
});
// Fonts
gulp.task('fonts', () => {
gulp.src('public/assets/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
});
// File watchers
gulp.task('watch', ['browserSync', 'sass'], () => {
gulp.watch('public/assets/scss/**/*.scss', ['sass']);
gulp.watch('public/*.html', browserSync.reload);
gulp.watch('public/assets/js/**/*.js', browserSync.reload);
gulp.watch('public/app/**/*.js', browserSync.reload);
});
// Cleaning generated files
gulp.task('clean:dist', () => {
del.sync('dist');
});
// Cache clearing
gulp.task('cache:clear', (callback) => {
cache.clearAll(callback);
});