-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
159 lines (128 loc) · 3.66 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"use strict"
const {src, dest} = require("gulp")
const gulp = require("gulp")
const browsersync = require("browser-sync").create()
const del = require("del")
const autoprefixer = require("gulp-autoprefixer")
const cssbeautify = require("gulp-cssbeautify")
const cssnano = require("gulp-cssnano")
const imagemin = require("gulp-imagemin")
const less = require("gulp-less")
const plumber = require("gulp-plumber")
const rename = require("gulp-rename")
const rigger = require("gulp-rigger")
const sass = require("gulp-sass")
const removeComments = require("gulp-strip-css-comments")
const uglify = require("gulp-uglify")
const panini = require("panini")
/* Paths */
let path = {
build: {
html: "dist/",
js: "dist/assets/js/",
css: "dist/assets/css/",
images: "dist/assets/img/"
},
src: {
html: "src/*.html",
js: "src/assets/js/*.js",
css: "src/assets/less/style.less",
images: "src/assets/img/**/*.{jpg,png,svg,gif,ico}"
},
watch: {
html: "src/**/*.html",
js: "src/assets/js/**/*.js",
css: "src/assets/less/**/*.less",
images: "src/assets/img/**/*.{jpg,png,svg,gif,ico}"
},
clean: "./dist"
}
/* Tasks */
function browserSync(done) {
browsersync.init({
server: {
baseDir: "./dist/"
},
port: 3000
})
}
function browserSyncReload(done) {
browsersync.reload()
}
function html() {
panini.refresh()
return src(path.src.html, {base: "src/"})
.pipe(plumber())
.pipe(panini({
root: 'src/',
layouts: 'src/templates/layouts/',
partials: 'src/templates/partials/',
helpers: 'src/templates/helpers/',
data: 'src/templates/data/'
}))
.pipe(dest(path.build.html))
.pipe(browsersync.stream())
}
function css() {
return src(path.src.css, {base: "src/assets/less/"})
.pipe(plumber())
.pipe(less())
.pipe(autoprefixer({
Browserslist: ['last 8 versions'],
cascade: true
}))
.pipe(cssbeautify())
.pipe(dest(path.build.css))
.pipe(cssnano({
zindex: false,
discardComments: {
removeAll: true
}
}))
.pipe(removeComments())
.pipe(rename({
suffix: ".min",
extname: ".css"
}))
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}
function js() {
return src(path.src.js, {base: './src/assets/js/'})
.pipe(plumber())
.pipe(rigger())
.pipe(dest(path.build.js))
.pipe(uglify())
.pipe(rename({
suffix: ".min",
extname: ".js"
}))
.pipe(dest(path.build.js))
.pipe(browsersync.stream())
}
function images() {
return src(path.src.images)
//.pipe(imagemin())
.pipe(gulp.dest(path.build.images))
.pipe(browsersync.stream())
}
function clean() {
return del(path.clean)
}
function watchFiles() {
gulp.watch([path.watch.html], html)
gulp.watch([path.watch.css], css)
gulp.watch([path.watch.js], js)
gulp.watch([path.watch.images], images)
}
const build = gulp.series(clean, gulp.parallel(html, css, js, images))
const watch = gulp.parallel(build, watchFiles, browserSync)
/* Exports Tasks */
exports.html = html
exports.css = css
exports.js = js
exports.images = images
exports.clean = clean
exports.build = build
exports.watch = watch
exports.default = watch