-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
98 lines (88 loc) · 2.46 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
const gulp = require('gulp');
const { series, parallel } = require('gulp');
const fs = require('fs');
const yaml = require('js-yaml');
const ejs = require('gulp-ejs');
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const uglify = require('gulp-uglify-es').default;
const plumber = require('gulp-plumber');
const notify = require('gulp-notify');
const browserSync = require('browser-sync');
function build_ejs(cb) {
const data = yaml.load(fs.readFileSync('./config.yaml', 'utf8'));
gulp
.src(['./src/**/*.ejs', '!' + './src/**/_*.ejs'])
.pipe(plumber(notify.onError('Error: <%= error.message %>')))
.pipe(ejs(data))
.pipe(
rename({
extname: '.html',
})
)
.pipe(gulp.dest('./dist/'));
cb();
}
exports.build_ejs = build_ejs;
function build_sass(cb) {
gulp
.src(['./src/**/*.sass', './src/**/*.scss'])
.pipe(plumber(notify.onError('Error: <%= error.message %>')))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest('./dist/'));
cb();
}
exports.build_sass = build_sass;
function build_js(cb) {
gulp
.src(['./src/**/*.js'])
.pipe(plumber(notify.onError('Error: <%= error.message %>')))
.pipe(uglify())
.pipe(gulp.dest('./dist/'));
cb();
}
exports.build_js = build_js;
function build_img(cb) {
gulp
.src(['./src/img/**/*'])
.pipe(plumber(notify.onError('Error: <%= error.message %>')))
.pipe(gulp.dest('./dist/img/'));
cb();
}
exports.build_img = build_img;
function browser_sync(cb) {
browserSync({
server: {
baseDir: './dist/',
},
});
cb();
}
exports.browser_sync = browser_sync;
function bs_reload(cb) {
browserSync.reload();
cb();
}
exports.bs_reload = bs_reload;
function clean(cb) {
fs.promises.rm('./dist/', {
recursive: true,
force: true,
});
cb();
}
exports.clean = clean;
function watch(cb) {
gulp.watch(['./config.yaml', './src/**/*.ejs'], build_ejs);
gulp.watch(['./src/**/*.sass', './src/**/*.scss'], build_sass);
gulp.watch(['./src/**/*.js'], build_js);
gulp.watch(['./src/img/**/*'], build_img);
gulp.watch(['./dist/**/*'], bs_reload);
cb();
}
exports.watch = watch;
exports.build = parallel(build_ejs, build_sass, build_js, build_img);
exports.default = series(parallel(build_ejs, build_sass, build_js, build_img), browser_sync, watch);