-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
83 lines (69 loc) · 1.81 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
78
79
80
81
82
83
const gulp = require('gulp');
const browserSync = require('browser-sync');
const sass = require('@selfisekai/gulp-sass');
const postcss = require('gulp-postcss');
const prefix = require('autoprefixer');
const concat = require('gulp-concat');
const babel = require('gulp-babel');
sass.compiler = require('sass');
const startServer = (done) => {
browserSync.init({
server: "./",
port: 2314
})
done()
}
const browserSyncReload = (done) => {
browserSync.reload()
done()
}
const compileScripts = () => {
return gulp.src(['js/*.js', 'js/custom.js'])
.pipe(babel({
"presets": [ "@babel/preset-env" ]
}))
.pipe(concat('scripts.js'))
.pipe(gulp.dest('./'))
.pipe(browserSync.reload({ stream:true }))
}
const compileStyles = () => {
const plugins = [
prefix()
]
return gulp.src('scss/styles.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(postcss(plugins))
.pipe(gulp.dest('./'))
.pipe(browserSync.reload({ stream:true }))
}
const watchMarkup = () => {
gulp.watch(['index.html'], browserSyncReload);
}
const watchScripts = () => {
gulp.watch(['js/*.js'], compileScripts);
}
const watchStyles = () => {
gulp.watch(['scss/*.scss'], compileStyles)
}
const compile = gulp.parallel(compileScripts, compileStyles)
compile.description = 'compile all sources'
// Not exposed to CLI
const serve = gulp.series(compile, startServer)
serve.description = 'serve compiled source on local server at port 3000'
const watch = gulp.parallel(watchMarkup, watchScripts, watchStyles)
watch.description = 'watch for changes to all source'
const defaultTasks = gulp.parallel(serve, watch)
export {
compile,
compileScripts,
compileStyles,
serve,
watch,
watchMarkup,
watchScripts,
watchStyles,
}
export default defaultTasks