-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
99 lines (83 loc) · 2.51 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const gulp = require("gulp")
const sass = require("gulp-sass")
const browserSync = require("browser-sync").create()
const imagemin = require("gulp-imagemin")
const cache = require("gulp-cache")
const del = require("del")
const runSequence = require("run-sequence")
const cleanCSS = require("gulp-clean-css")
const uglify = require("gulp-uglify")
const htmlmin = require("gulp-htmlmin")
const rollup = require("gulp-better-rollup")
const babel = require("rollup-plugin-babel")
gulp.task("images", () => {
gulp
.src("_src/images/**/*.+(png|jpg|jpeg|gif|svg)")
.pipe(cache(imagemin()))
.pipe(gulp.dest("dist/images"))
return del.sync("dist/images")
})
gulp.task("js", () => {
gulp
.src("_src/sw.js")
.pipe(rollup({ plugins: [babel()] }, { format: "cjs" }))
.pipe(uglify())
.pipe(gulp.dest("dist/"))
gulp
.src("_src/js/stats.js")
.pipe(rollup({ plugins: [babel()] }, { format: "cjs" }))
.pipe(uglify())
.pipe(gulp.dest("dist/js"))
return gulp
.src("_src/js/gamingtrivia.js")
.pipe(rollup({ plugins: [babel()] }, { format: "cjs" }))
.pipe(uglify())
.pipe(gulp.dest("dist/js"))
.pipe(browserSync.reload({ stream: true }))
})
gulp.task("scss", () => {
gulp
.src("_src/scss/stats.scss")
.pipe(sass())
.pipe(cleanCSS())
.pipe(gulp.dest("dist/css"))
return gulp
.src("_src/scss/gamingtrivia.scss")
.pipe(sass())
.pipe(cleanCSS())
.pipe(gulp.dest("dist/css"))
.pipe(browserSync.reload({ stream: true }))
})
gulp.task("html", () => {
gulp
.src("_src/**/*.html")
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest("dist/"))
.pipe(browserSync.reload({ stream: true }))
return del.sync("dist/**/*.html")
})
gulp.task("files", () => {
gulp.src("_src/**/*.+(json|txt|xml)").pipe(gulp.dest("dist/"))
return del.sync("dist/**/*.+(json|txt|xml)")
})
gulp.task("syncDist", () => del.sync("dist"))
gulp.task("browserSync", () =>
browserSync.init({ server: { baseDir: "./dist" } })
)
gulp.task("watch", () => {
gulp.watch("_src/images/**/*.+(png|jpg|jpeg|gif|svg)", ["images"])
gulp.watch("_src/js/**/*.js", ["js"])
gulp.watch("_src/scss/**/*.scss", ["scss"])
gulp.watch("_src/**/*.html", ["html"])
gulp.watch("_src/**/*.+(json|txt|xml)", ["files"])
})
gulp.task("build", (callback) => {
runSequence(["images", "js", "scss", "html", "files"], callback)
})
gulp.task("default", (callback) => {
runSequence(
"syncDist",
["images", "js", "scss", "html", "files", "browserSync", "watch"],
callback
)
})