-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
128 lines (113 loc) · 3.85 KB
/
gulpfile.babel.js
File metadata and controls
128 lines (113 loc) · 3.85 KB
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
const gulp= require('gulp');
const gulpLoadPlugins= require('gulp-load-plugins');
const browserSync= require('browser-sync');
const childProcess= require('child_process');
const webpack= require('webpack2-stream-watch');
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
// =======================
// TASKS FOR DEVELOPMENT
// =======================
// Starts browsersync and file watching
gulp.task('serve', ['browser-sync'], () => {
gulp.watch(['src/_sass/**/*.scss','src/css/*.scss'], ['sass']);
gulp.watch(['src/_js/**/*.js'], ['js']);
gulp.watch(['src/_assets/**/*'], ['imagemin']);
gulp.watch(['src/graveyard/**/*', 'src/_data/*', 'src/*.html', 'src/*.md', 'src/_plugins/**/*.*', 'src/_layouts/*', 'src/_includes/**/*.*', 'src/_posts/**/*.*', 'src/_drafts/**/*.*', 'src/_pages/**/*.*'], ['build:reload']);
});
// Builds Jekyll site (including drafts)
gulp.task('build', done => {
return childProcess.spawn('jekyll', ['build', '--drafts'], {stdio: 'inherit'})
.on('close', done);
});
// First runs jekyll build task, then reloads browser
gulp.task('build:reload', ['build'], () => { reload(); });
// ======================
// TASKS FOR DEPLOYMENT
// ======================
// First run htmlmin, then deploy to github
gulp.task('deploy', ['htmlmin'], () => {
return gulp.src('./dist/**/*').pipe($.ghPages({branch: 'prod'}));
});
// First run build:prod and then minify HTML
gulp.task('htmlmin', ['build:prod'], () => {
return gulp.src('./dist/**/*.html')
.pipe($.htmlmin( {collapseWhitespace: true}))
.pipe(gulp.dest('./dist/'))
.pipe(reload({stream: true}));
});
// Runs jekyll build for 'production' environment
gulp.task('build:prod', ['js', 'sass', 'imagemin'], done => {
var productionEnv = process.env;
productionEnv.JEKYLL_ENV = 'production';
return childProcess.spawn('jekyll', ['build', '--config', '_config.yml,_config.build.yml'], {stdio: 'inherit' , env: productionEnv}).on('close', done);
});
// ====================
// OTHER USEFUL TASKS
// ====================
// Browser sync + styles for the notification
gulp.task('browser-sync', ['js', 'sass', 'imagemin', 'build'], () => {
browserSync({
notify: {
styles: [
'font-weight: bold;',
'padding: 10px;',
'margin: 0;',
'position: fixed;',
'font-size: 0.6em;',
'line-height: 0.8em;',
'z-index: 9999;',
'left: 5px;',
'top: 5px;',
'color: #fff;',
'border-radius: 2px',
'background-color: #333;',
'background-color: rgba(50,50,50,0.8);'
]
},
server: {
baseDir: 'dist'
}
});
});
// Compile sass + livereload with css injection + minificiation
gulp.task('sass', () => {
return gulp.src('src/css/main.scss')
.pipe($.sass({
includePaths: ['src/_sass'],
onError: browserSync.notify
}))
.pipe($.autoprefixer(['last 15 versions', '> 1%', 'ie 8'], {cascade: true}))
.pipe($.rename('main.css'))
.pipe(gulp.dest('dist/css'))
.pipe(reload({stream: true}))
.pipe($.minifyCss({keepBreaks: false, keepSpecialComments:true}))
.pipe($.rename({extname: '.min.css'}))
.pipe(gulp.dest('dist/css'));
});
// Compile JavaScript files + uglifies files
gulp.task('js', () => {
return gulp.src('src/_js/**/*.js')
.pipe(webpack({
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: '/node_modules/',
query: { compact: false }
}]
}
}))
.pipe($.rename('main.js'))
.pipe(gulp.dest('dist/scripts'))
.pipe(reload({stream: true}))
.pipe($.uglify({onError: browserSync.notify}))
.pipe($.rename({extname: '.min.js'}))
.pipe(gulp.dest('dist/scripts'));
});
// Optimise images + copy any other assets
gulp.task('imagemin', () => {
return gulp.src('src/_assets/**/*')
.pipe($.imagemin())
.pipe(gulp.dest('dist/assets'));
});