-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (59 loc) · 1.78 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
const gulp = require('gulp');
const babel = require('gulp-babel');
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const plumber = require('gulp-plumber');
const sequence = require('gulp-sequence');
const notify = require('gulp-notify');
const del = require('del');
const nodemon = require('gulp-nodemon');
const livereload = require('gulp-livereload');
const src = 'src';
const dist = 'public';
function reportError(error) {
//trigger Mac os notifications
notify({
title: `Task Failed [${error.plugin}]`,
message: 'Check the console'
}).write(error);
//log the error in the terminal
console.log(error.toString());
//prevents having to restart Gulp after a crash
this.emit('end');
}
gulp.task('clean', () => {
return del([`${dist}/css`, `${dist}/js`, `${dist}/assets`]);
});
gulp.task('nodemon', () => {
return nodemon({
script: 'server.js',
ext: 'js html',
env: { 'NODE_ENV': 'development' }
});
});
gulp.task('scripts', () => {
return gulp.src(`${src}/**/*.js`)
.pipe(plumber({ errorHandler: reportError }))
.pipe(babel({ presets: ['es2015'] }))
.pipe(gulp.dest(dist))
.pipe(livereload());
});
gulp.task('sass', () => {
return gulp.src(`${src}/**/style.scss`)
.pipe(plumber({ errorHandler: reportError }))
.pipe(sass())
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(gulp.dest(dist))
.pipe(livereload());
});
gulp.task('assets', () => {
return gulp.src(`${src}/assets/**/*`)
.pipe(gulp.dest(`${dist}/assets`));
});
gulp.task('watch', () => {
livereload.listen();
gulp.watch(`${src}/**/*.js`, ['scripts']);
gulp.watch(`${src}/**/*.scss`, ['sass']);
gulp.watch(`${src}/assets/**/*`, ['assets']);
});
gulp.task('default', sequence('clean', ['scripts', 'sass', 'assets'], 'watch', 'nodemon'));