forked from keystonejs/keystone-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (67 loc) · 1.88 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
var _ = require('underscore'),
gulp = require('gulp'),
gutil = require('gulp-util'),
watch = require('gulp-watch'),
browserify = require('browserify'),
shimify = require('browserify-shim'),
uglify = require('gulp-uglify'),
watchify = require('watchify'),
reactify = require('reactify'),
source = require('vinyl-source-stream'),
chalk = require('chalk'),
del = require('del'),
streamify = require('gulp-streamify');
/**
* Build Tasks
*/
// build scripts with browserify and react / jsx transforms
gulp.task('build-scripts', function() {
return browserify({
standalone: 'App'
})
.add('./admin/src/app.js')
.transform(reactify)
.transform(shimify)
.bundle()
.on('error', function(e) {
gutil.log('Browserify Error', e);
})
.pipe(source('app.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('./public/build/js'));
});
// watch scripts & build with debug features
gulp.task('watch-scripts', function() {
var b = browserify(_.defaults({
standalone: 'App',
debug: true
}, watchify.args))
.add('./admin/src/app.js')
.transform(reactify)
.transform(shimify);
var w = watchify(b)
.on('update', function (scriptIds) {
scriptIds = scriptIds
.filter(function(i) { return i.substr(0,2) !== './'; })
.map(function(i) { return chalk.blue(i.replace(__dirname, '')); });
if (scriptIds.length > 1) {
gutil.log(scriptIds.length + ' Scripts updated:\n* ' + scriptIds.join('\n* ') + '\nrebuilding...');
} else {
gutil.log(scriptIds[0] + ' updated, rebuilding...');
}
rebundle();
})
.on('time', function (time) {
gutil.log(chalk.green('Scripts built in ' + (Math.round(time / 10) / 100) + 's'));
});
function rebundle() {
w.bundle()
.on('error', function(e) {
gutil.log('Browserify Error', e);
})
.pipe(source('app.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('./public/build/js'));
}
return rebundle();
});