-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
79 lines (65 loc) · 1.74 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
'use strict';
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const runSequence = require('run-sequence').use(gulp);
const $ = require('gulp-load-plugins')();
const opts = require('./config/gulp');
const rev = require('gulp-rev');
const revdel = require('gulp-rev-delete-original');
const del = require('del');
for (const task of fs.readdirSync('./tasks')) {
const file = path.join('./tasks', task);
const taskModule = require(path.resolve(file));
if (typeof taskModule == 'function') {
taskModule(gulp, $, opts);
}
}
gulp.task('build', function(cb) {
const buildTasks = ['templates', 'precompile', 'browserify', 'css', 'images'];
let tasks = buildTasks;
if (process.env.NODE_ENV === 'production') {
tasks = [
'build.clean',
...buildTasks,
'rev',
'sitemap',
];
}
runSequence.apply(this, tasks.concat(cb));
});
gulp.task('build.clean', function() {
return del(['build', 'public/{*.js,*.css,images}']);
});
gulp.task('rev', function () {
gulp
.src(['public/app.js', 'public/app.css'])
.pipe(rev())
.pipe(revdel())
.pipe(gulp.dest('public'))
.pipe(rev.manifest())
.pipe(gulp.dest('build'));
});
gulp.task('dev', function(cb) {
opts.devMode = true;
const tasks = _.compact([
'build',
'server',
'watch',
'interactivity',
opts.enableNotifier ? 'notifier' : null,
]);
runSequence.apply(this, tasks.concat(cb));
});
gulp.task('default', ['build']);
function handleErrors(err) {
if (err) {
console.error(err && err.stack);
}
process.exitCode = 1;
$.util.beep();
}
process.on('unhandledRejection', handleErrors);
process.on('uncaughtException', handleErrors);
gulp.on('err', handleErrors);