-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
gulpfile.js
90 lines (78 loc) · 2.29 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
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const htmlmin = require('gulp-htmlmin');
const cssmin = require('gulp-cssmin');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const concat = require('gulp-concat');
const jsImport = require('gulp-js-import');
const sourcemaps = require('gulp-sourcemaps');
const htmlPartial = require('gulp-html-partial');
const clean = require('gulp-clean');
const isProd = process.env.NODE_ENV === 'prod';
const htmlFile = [
'src/*.html'
]
function html() {
return gulp.src(htmlFile)
.pipe(htmlPartial({
basePath: 'src/partials/'
}))
.pipe(gulpIf(isProd, htmlmin({
collapseWhitespace: true
})))
.pipe(gulp.dest('docs'));
}
function css() {
return gulp.src('src/sass/style.scss')
.pipe(gulpIf(!isProd, sourcemaps.init()))
.pipe(sass({
includePaths: ['node_modules']
}).on('error', sass.logError))
.pipe(gulpIf(!isProd, sourcemaps.write()))
.pipe(gulpIf(isProd, cssmin()))
.pipe(gulp.dest('docs/css/'));
}
function js() {
return gulp.src('src/js/*.js')
.pipe(jsImport({
hideConsole: true
}))
.pipe(concat('all.js'))
.pipe(gulpIf(isProd, uglify()))
.pipe(gulp.dest('docs/js'));
}
function img() {
return gulp.src('src/img/*')
.pipe(gulpIf(isProd, imagemin()))
.pipe(gulp.dest('docs/img/'));
}
function serve() {
browserSync.init({
open: true,
server: './docs'
});
}
function browserSyncReload(done) {
browserSync.reload();
done();
}
function watchFiles() {
gulp.watch('src/**/*.html', gulp.series(html, browserSyncReload));
gulp.watch('src/**/*.scss', gulp.series(css, browserSyncReload));
gulp.watch('src/**/*.js', gulp.series(js, browserSyncReload));
gulp.watch('src/img/**/*.*', gulp.series(img));
return;
}
function del() {
return gulp.src('docs/*', {read: false})
.pipe(clean());
}
exports.css = css;
exports.html = html;
exports.js = js;
exports.del = del;
exports.serve = gulp.parallel(html, css, js, img, watchFiles, serve);
exports.default = gulp.series(del, html, css, js, img);