-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.babel.js
89 lines (75 loc) · 1.95 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
84
85
86
87
88
89
const gulp = require("gulp");
const browserSync = require("browser-sync");
const sass = require("@selfisekai/gulp-sass");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
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/custom.js")
.pipe(
babel({
presets: ["@babel/preset-env"],
})
)
.pipe(concat("scripts.js"))
.pipe(gulp.dest("./"))
.pipe(browserSync.reload({ stream: true }));
};
const compileStyles = () => {
const plugins = [autoprefixer(), cssnano()];
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;