-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
151 lines (135 loc) · 3.54 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
const gulp = require('gulp'),
sass = require('gulp-sass'),
prefix = require('gulp-autoprefixer'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
hb = require('gulp-handlebars-all'),
imagemin = require('gulp-imagemin'),
newer = require('gulp-newer'),
rename = require('gulp-rename'),
markdown = require('gulp-markdown'),
inject = require('gulp-inject-string'),
browsersync = require('browser-sync').create()
const helpers = require('handlebars-helpers')();
function browserSync(done) {
browsersync.init({
server: {
baseDir: './build/'
},
port: 3000
})
done()
}
function md() {
return gulp.src('./md/**/*.md')
.pipe(markdown())
.pipe(inject.prepend(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>F4PGA</title>
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body class="article">
`))
.pipe(inject.append(`
</body>
</html>
`))
.pipe(gulp.dest('./build'))
.pipe(browsersync.stream())
}
function images() {
return gulp
.src('./assets/img/**/*')
.pipe(newer('./build/assets/img'))
.pipe(
imagemin([
imagemin.gifsicle({
interlaced: true
}),
imagemin.jpegtran({
progressive: true
}),
imagemin.optipng({
optimizationLevel: 5
}),
imagemin.svgo({
plugins: [{
removeViewBox: false,
collapseGroups: true
}]
})
])
)
.pipe(gulp.dest('./build/assets/img'))
}
function imagesMove() {
return gulp
.src('./assets/img/**/*')
.pipe(newer('./build/assets/img'))
.pipe(gulp.dest('./build/assets/img'))
.pipe(browsersync.stream())
}
function scss() {
return gulp
.src('./assets/scss/*.scss')
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(prefix())
.pipe(gulp.dest('./build/assets/css/'))
.pipe(browsersync.stream())
}
function css() {
return gulp
.src('./assets/css/*.css')
.pipe(gulp.dest('./build/assets/css/'))
}
function scripts() {
return gulp
.src('./assets/js/**/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(gulp.dest('./build/assets/js/'))
.pipe(browsersync.stream());
}
function handlebars() {
delete require.cache[require.resolve('./assets/data/data.json')]
return gulp
.src('./*.hbs')
.pipe(hb('html', {
context: require('./assets/data/data.json')
}))
.pipe(rename(path => path.extname = '.html'))
.pipe(gulp.dest('./build'))
.pipe(browsersync.stream());
}
function watchFiles() {
gulp.watch('./assets/fonts/**/*', fonts)
gulp.watch('./assets/scss/**/*', scss)
gulp.watch('./assets/css/**/*', css)
gulp.watch('./assets/js/**/*', scripts)
gulp.watch(['./*.hbs', './assets/data/data.json'], handlebars)
gulp.watch('./assets/img/**/*', images)
gulp.watch('./md/**/*.md', md)
}
function fonts() {
return gulp
.src('./assets/fonts/**/*')
.pipe(gulp.dest('./build/assets/fonts'))
}
const build = gulp.parallel(scss, css, scripts, images, fonts, handlebars, md, () => {
return gulp
.src('./**/*.html')
.pipe(gulp.dest('./build'))
}),
watch = gulp.series(gulp.parallel(scss, css, scripts, imagesMove, fonts, handlebars), gulp.parallel(watchFiles, browserSync))
exports.build = build
exports.watch = watch
exports.markdown = md