-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (65 loc) · 2.07 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
const gulp = require('gulp');
const babel = require('gulp-babel');
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync').create();
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const sourcemaps = require('gulp-sourcemaps');
const nodemon = require('gulp-nodemon');
const clean = require('gulp-clean');
const sequence = require('run-sequence');
function reportError(error) {
notify({
title: `Task Failed [${error.plugin}]`,
message: 'Check the terminal.'
}).write(error);
console.log(error.toString());
this.emit('end');
}
gulp.task('clean', () => {
return gulp.src('public/**/*.*', { read: false })
.pipe(clean());
});
gulp.task('es6', () => {
return gulp.src('src/js/*.js')
.pipe(plumber({ errorHandler: reportError }))
.pipe(sourcemaps.init())
.pipe(babel({ presets: ['es2015'] }))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/js'));
});
gulp.task('sass', () => {
return gulp.src('src/scss/**/*.scss')
.pipe(plumber({ errorHandler: reportError }))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({ compatibility: 'ie8'}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/css'));
});
gulp.task('assets', () => {
return gulp.src('src/assets/**/*')
.pipe(gulp.dest('public/assets'));
});
gulp.task('serve', sequence('clean', ['es6', 'sass']), () => {
browserSync.init({
proxy: 'http://localhost:3000',
port: 8000,
files: ['public/**/*.*', 'views/**/*.*'],
reloadDelay: 500
});
return nodemon().on('start', () => browserSync.reload());
});
gulp.task('watch', () => {
gulp.watch('src/scss/**/*.scss', ['sass']);
gulp.watch('src/js/*.js', ['es6']);
gulp.watch('src/assets/**/*', ['assets']);
});
const defaultTask = () => {
return gulp.start(['serve', 'watch']);
};
gulp.task('build', sequence('clean', ['sass', 'es6', 'assets']));
gulp.task('default', ['build'], defaultTask);