-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (71 loc) · 1.91 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
// Initialize modules
const { src, dest, watch, series, parallel } = require("gulp")
// Import packages
const postcss = require("gulp-postcss")
const autoprefixer = require("autoprefixer")
const cssnano = require("cssnano")
const replace = require("gulp-replace")
const browser_sync = require("browser-sync").create()
// Files path
const files = {
cssPath: "src/css/*.css",
}
/* Css task
1. Add vendor prefixes
2. Minify css
============ */
function css_task() {
return src(files.cssPath)
.pipe(postcss([autoprefixer("last 4 versions"), cssnano()]))
.pipe(dest("dist/css"))
}
// Cachebust task
function cachebust_task() {
let timeString = new Date().getTime()
return src(["index.html"])
.pipe(replace(/cb=\d+/g, "cb=" + timeString))
.pipe(dest("."))
}
// CopyCss vendors task
function copyCss_task() {
return src(["src/css/vendors/**/*"], { "base": "src/css" })
.pipe(dest("dist/css"))
}
// CopyImage task
function copyImage_task() {
return src(["src/images/favicon/*"], { "base": "src/images" })
.pipe(dest("dist/images"))
}
// Initialize browserSync
function browserSync(callback) {
browser_sync.init({
server: {
baseDir: "."
},
notify: {
styles: {
top: "auto",
bottom: "0"
}
}
})
callback()
}
// Reload browserSync
function browserSyncReload(callback) {
browser_sync.reload()
callback()
}
// BrowserSync watch task
function browserSyncWathc() {
watch(["index.html"], browserSyncReload)
watch([files.cssPath], series(parallel(css_task), cachebust_task))
}
// Gulp watch task
function watch_Tasks() {
watch([files.cssPath], series(parallel(css_task), cachebust_task))
}
// Gulp default task
exports.default = series(parallel(css_task), cachebust_task, copyCss_task, copyImage_task, watch_Tasks)
// Run browserSync
exports.bs = series(parallel(css_task), cachebust_task, copyCss_task, copyImage_task, browserSync, browserSyncWathc)