-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (89 loc) · 2.28 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
const
gulp = require('gulp'),
gconcat = require('gulp-concat'),
gplumber = require('gulp-plumber'),
gsass = require('gulp-sass'),
gprefix = require('gulp-autoprefixer'),
guglify = require('gulp-uglify'),
gorder = require('gulp-order'),
gimagemin = require('gulp-imagemin'),
gbabel = require('gulp-babel'),
gdeploy = require('gulp-gh-pages'),
cp = require('child_process')
let
bundleCommand = 'bundle',
jekyllOption = ['exec', 'jekyll', 'build']
const app = {
sass: {
main: 'src/sass/main.scss',
src: 'src/sass/**/*.scss',
dest: 'assets/css/'
},
script: {
src: 'src/js/**/*.js',
dest: 'assets/js/',
order: [
"src/js/vendor/jquery.js",
"src/js/vendor/**/*.js",
"src/js/**/*.js"
]
},
imagemin: {
src: 'src/img/**/*.{jpg,jpeg,png,gif}',
dest: 'assets/img/'
},
jekyll: {
src: ['*.html', '_includes/*.html', '_layouts/*.html', '_posts/*', '_config.yml']
}
}
const jekyll = done => {
return cp.spawn(bundleCommand, jekyllOption, {stdio: 'inherit'}).on('close', done)
}
const jekyllRebuild = () => {
jekyllOption = ['exec', 'jekyll', 'build']
return jekyll
}
const sass = () => {
return gulp.src(app.sass.main)
.pipe(gplumber())
.pipe(gsass({outputStyle: 'compressed'}))
.pipe(gprefix())
.pipe(gulp.dest(app.sass.dest))
}
const script = () => {
return gulp.src(app.script.src, { sourcemaps: true })
.pipe(gplumber())
.pipe(gorder(app.script.order, { base: './' }))
.pipe(gbabel({
presets: ['@babel/preset-env'],
ignore: ['src/js/vendor/**/*.js']
}))
.pipe(guglify()) // {mangle: true}
.pipe(gconcat('main.js'))
.pipe(gulp.dest(app.script.dest))
}
const imagemin = () => {
return gulp.src(app.imagemin.src)
.pipe(gplumber())
.pipe(gimagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(app.imagemin.dest))
}
const build = gulp.series(gulp.parallel(sass, script, imagemin), jekyll)
const deploy = () => {
return gulp.src('_site/**/*').pipe(gdeploy({branch: 'master'}))
}
const watch = () => {
jekyllOption = ['exec', 'jekyll', 'server', '--host=0.0.0.0']
build()
gulp.watch(app.sass.src, sass)
gulp.watch(app.script.src, script)
gulp.watch(app.imagemin.src, imagemin)
gulp.watch(app.jekyll.src, jekyllRebuild)
}
gulp.task('build', build)
gulp.task('deploy', deploy)
gulp.task('default', watch)