-
Notifications
You must be signed in to change notification settings - Fork 14
/
Gulpfile.js
136 lines (121 loc) · 3.55 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
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var cp = require('child_process');
var sourcemaps = require('gulp-sourcemaps');
var babelify = require('babelify');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var imagemin = require('gulp-imagemin');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-develop', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('jekyll-build', function (done) {
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-develop'], function () {
browserSync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browser-sync', ['sass-develop', 'js-develop', 'jekyll-develop'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
/**
* Compile files from _scss
*/
gulp.task('sass-develop', function () {
return gulp.src('_sass/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 3 versions'], { cascade: true }))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('_site/css'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('sass-build', function () {
return gulp.src('_sass/main.scss')
.pipe(sass({
includePaths: ['scss']
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('_site/css'));
});
/**
* Compile files from _js
*/
gulp.task('js-develop', function () {
var bundler = browserify({
entries: '_js-es6/app.js',
debug: true
});
bundler.transform(babelify);
bundler.bundle()
.on('error', function (err) { console.error(err); })
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('_site/js'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('js-build', function () {
var bundler = browserify({
entries: '_js-es6/app.js',
debug: true
});
bundler.transform(babelify);
bundler.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(gulp.dest('_site/js'))
});
/**
* Copy and compress any site images
*/
gulp.task('copy-images', () =>
gulp.src('images/**/*.{jpg,png,svg}')
.pipe(imagemin())
.pipe(gulp.dest('_site/images'))
);
/**
* Watch scss files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch(['_js-es6/**/*.js'], ['js-develop']);
gulp.watch(['_sass/**/*.scss'], ['sass-develop']);
gulp.watch(['**/*.html', '**/*.markdown', '**/*.md'], ['jekyll-rebuild']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
/**
* Gulp 'build' task which is used to build the site on the production box.
*/
gulp.task('build', ['jekyll-build', 'sass-build', 'js-build']);