-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
162 lines (132 loc) · 4.62 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
160
161
162
/* =========================================
gulp plugins
========================================= */
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync');
const cleanCSS = require('gulp-clean-css');
const htmlmin = require('gulp-htmlmin');
const ghPages = require('gulp-gh-pages');
const gulp = require('gulp');
const mocha = require('gulp-spawn-mocha');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const shell = require('gulp-shell');
const webpack = require('webpack-stream');
const webpackDevConfig = require('./webpack-dev.config.js');
const webpackProdConfig = require('./webpack-prod.config.js');
/* =========================================
html
========================================= */
gulp.task('build:html', () =>
gulp
.src('_site/**/*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('_site/'))
);
/* =========================================
styles
========================================= */
gulp.task('build:styles', () =>
gulp
.src('source/_sass/styles.scss')
.pipe(plumber())
.pipe(sass())
.pipe(
autoprefixer({
Browserslist: ['last 2 versions', '> 5%', 'IE 9']
})
)
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename('style.min.css'))
.pipe(gulp.dest('source/assets/'))
.pipe(gulp.dest('_site/assets/'))
.pipe(browserSync.stream())
);
/* =========================================
images
========================================= */
/* =========================================
scripts
========================================= */
gulp.task('build:scripts:dev', () =>
gulp
.src('source/_js/scripts.js')
.pipe(plumber())
.pipe(webpack(webpackDevConfig))
.pipe(gulp.dest('source/assets/'))
.pipe(gulp.dest('_site/assets/'))
// .pipe(browserSync.stream())
);
gulp.task('build:scripts:prod', () =>
gulp
.src('source/_js/scripts.js')
.pipe(plumber())
.pipe(webpack(webpackProdConfig))
.pipe(gulp.dest('source/assets/'))
.pipe(gulp.dest('_site/assets/'))
);
/* =========================================
build dev
========================================= */
gulp.task('build:jekyll', shell.task('bundle exec jekyll build --incremental --config _config.yml,_config_dev.yml'));
gulp.task('build:jekyll:dev', gulp.series('build:jekyll', 'build:html'));
gulp.task('build:dev', gulp.series(gulp.series('build:scripts:dev', 'build:styles'), 'build:jekyll', 'build:html'));
/* =========================================
build prod
========================================= */
gulp.task('jekyll:clean', shell.task(['bundle exec jekyll clean']));
gulp.task('build:jekyll:prod', shell.task('bundle exec jekyll build'));
gulp.task(
'build:prod',
gulp.series('jekyll:clean', 'build:scripts:prod', 'build:styles', 'build:jekyll:prod', 'build:html')
);
/* =========================================
tests
========================================= */
gulp.task(
'html_proofer',
shell.task([
'bundle exec htmlproofer ./_site --allow-hash-href --disable-external --check-favicon --url-swap "/objectively-jekyll-boilerplate|:" --check-html'
])
);
gulp.task('test:html', gulp.series('build:jekyll:dev', 'html_proofer'));
gulp.task('test:es-lint', shell.task(['eslint ./source/_js/**/*.js']));
gulp.task('test:mocha', () => gulp.src('spec/**/*.spec.js').pipe(mocha()));
gulp.task('test', gulp.series('test:html', 'test:es-lint', 'test:mocha'), done => {
done();
});
/* =========================================
build
========================================= */
gulp.task('build', gulp.series('build:prod'));
/* =========================================
serve
========================================= */
// BrowserSync Reload
function browserSyncReload(done) {
browserSync.reload();
done();
}
gulp.task('build:jekyll:watch', gulp.series('build:jekyll:dev'), done => {
browserSync.reload();
done();
});
gulp.task('build:scripts:watch', gulp.series('build:scripts:dev'), done => {
browserSync.reload();
done();
});
gulp.task('serve', done => {
browserSync.init({
server: '_site',
ghostMode: false,
logFileChanges: true,
open: false
});
gulp.watch('source/**/*.scss', gulp.series('build:styles'));
gulp.watch('source/_js/*.js', gulp.series('build:scripts:dev', browserSyncReload));
gulp.watch(['source/**/*.html', '!_site/**/*.*'], gulp.series('build:jekyll:dev', browserSyncReload));
gulp.watch('_data/**.*+(yml|yaml|csv|json)', gulp.series('build:jekyll:dev', browserSyncReload));
done();
});
gulp.task('default', gulp.series('build:dev','serve'));