-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.esm.js
89 lines (76 loc) · 1.81 KB
/
gulpfile.esm.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
79
80
81
82
83
84
85
86
87
88
89
import gulp from 'gulp';
import sass from 'gulp-sass';
import del from 'del';
import nodemon from 'gulp-nodemon';
import browserSync from 'browser-sync';
import imagemin from 'gulp-imagemin';
import webpack from 'webpack-stream';
import cache from 'gulp-cache';
const server = browserSync.create();
function styles() {
return gulp
.src('./src/sass/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'))
.pipe(server.stream());
}
const scripts = () => {
return gulp
.src('./src/js/bundle.js')
.pipe(webpack({
mode: 'development',
output: {
filename: 'bundle.js'
}
}))
.pipe(gulp.dest('./dist/js'))
}
const clean = () => {
return del(['dist']);
}
const images = (cb) => {
gulp.src('./images/*')
.pipe(cache(imagemin({optimizationLevel: 3})))
.pipe(gulp.dest('./dist/images'));
cb();
}
const browser = () => {
server.init({
proxy: 'http://localhost:5000'
});
}
const reload = (done) => {
server.reload();
done();
}
const app = (done) => {
var called = false;
return nodemon({
script: 'server.js',
watch: ['server.js'],
ext: 'js json',
})
.on('start', function() {
if (!called) {
done();
browser();
}
called = true;
})
.on('restart', () => {
console.log('restarted!');
})
.on('crash', () => {
console.error('Application has crashed!\n');
stream.emit('restart', 10)
});
}
function watch(done) {
gulp.watch('./src/sass/**/*.scss', styles);
gulp.watch('./views/**/*.pug', reload);
gulp.watch('./src/js/**/*.js', gulp.series(scripts, reload));
gulp.watch('./images/**', gulp.series(images, reload));
done();
}
const dev = gulp.series(clean, gulp.parallel(images, scripts, styles), watch, app);
export default dev;