-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
74 lines (65 loc) · 1.9 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
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import del from 'del';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
const $ = gulpLoadPlugins({
DEBUG: true,
camelize: true,
});
const reload = browserSync.reload;
gulp.task('sass', () => {
return gulp.src('app/public/scss/*.scss')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('build/css'))
.pipe(reload({stream:true}));
});
gulp.task('scripts', () => {
return gulp.src(['app/public/scripts/**/*.js', '!app/public/scripts/sw/sw.js'])
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('build/scripts'))
.pipe(reload({stream:true}));
});
gulp.task('sw', () => {
return gulp.src('app/public/scripts/sw/sw.js')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('build'))
.pipe(reload({stream:true}));
});
gulp.task('browser-sync', function() {
browserSync.init({
server: "./build"
});
});
gulp.task('watch', function() {
gulp.watch('app/public/scss/*.scss', ['sass']);
gulp.watch('app/public/scripts/**/*.js', ['scripts']);
gulp.watch('app/*.html', ['copy:html']);
})
gulp.task('copy:html', function() {
return gulp.src('app/index.html')
.pipe(gulp.dest('build'))
.pipe(reload({stream:true}));
})
gulp.task('clean', function() {
del(['build']).then(() => {
console.log('Cleaned build directory.')
});
})
gulp.task('serve', function() {
runSequence('clean', ['sass', 'scripts', 'sw', 'copy:html'], ['browser-sync', 'watch'])
})