-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
99 lines (82 loc) · 2.63 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
var atImport = require("postcss-import")
var autoprefixer = require("autoprefixer")
var browserSync = require("browser-sync").create()
var concat = require("gulp-concat")
var csswring = require("csswring")
var del = require("del")
var gulp = require("gulp")
var minifyHTML = require("gulp-minify-html")
var path = require("path")
var postcss = require("gulp-postcss")
var uglify = require("gulp-uglify")
var publicDir = path.join(__dirname, "public")
var srcDir = path.join(__dirname, "src")
gulp.task("browser-sync", ["build"], function () {
browserSync.init({
port: 6590,
server: {
baseDir: "public",
index: "index.html"
}
})
})
gulp.task("build", ["html", "css", "js", "img"])
gulp.task("clean-css", function () {
return del(path.join(publicDir, "css", "**", "*.css"))
})
gulp.task("clean-html", function () {
return del(path.join(publicDir, "*.html"))
})
gulp.task("clean-img", function () {
return del(path.join(publicDir, "img", "*.*"))
})
gulp.task("clean-js", function () {
return del(path.join(publicDir, "js", "**", "*.js"))
})
gulp.task("css", ["clean-css"], function (cb) {
var processors = [
atImport,
autoprefixer({browsers: [
"last 3 version"
]}),
csswring
]
return gulp
.src(path.join(srcDir, "css", "*.css"))
.pipe(postcss(processors))
.pipe(gulp.dest(path.join(publicDir, "css")))
.pipe(browserSync.stream())
})
gulp.task("css-watch", ["css"])
gulp.task("html", ["clean-html"], function () {
return gulp
.src(path.join(srcDir, "*.html"))
.pipe(minifyHTML())
.pipe(gulp.dest(publicDir))
.pipe(browserSync.stream())
})
gulp.task("html-watch", ["html"], browserSync.reload)
gulp.task("img", ["clean-img"], function () {
return gulp
.src(path.join(srcDir, "img", "*.*"))
.pipe(gulp.dest(path.join(publicDir, "img")))
})
gulp.task("js", ["clean-js"], function () {
return gulp
.src([
path.join(srcDir, "js", "vendor", "jquery.min.js"),
path.join(srcDir, "js", "vendor", "foundation.min.js"),
path.join(srcDir, "js", "*.js")
])
.pipe(concat("main.js"))
.pipe(uglify())
.pipe(gulp.dest(path.join(publicDir, "js")))
.pipe(browserSync.stream())
})
gulp.task("js-watch", ["js"], browserSync.reload)
gulp.task("watch", function () {
gulp.watch(path.join(srcDir, "*.html"), ["html-watch"])
gulp.watch(path.join(srcDir, "css", "*.css"), ["css-watch"])
gulp.watch(path.join(srcDir, "js", "*.js"), ["js-watch"])
})
gulp.task("server", ["browser-sync", "watch"])