-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
130 lines (111 loc) · 3.34 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
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
reload = browserSync.reload,
nodemon = require('gulp-nodemon'),
browserify = require('browserify'),
watchify = require('watchify'),
source = require('vinyl-source-stream'),
babelify = require('babelify'),
config = require('./tools/gulp/config'),
bundleLogger = require('./tools/gulp/util/bundleLogger'),
handleErrors = require('./tools/gulp/util/handleErrors')
gulp.task('default', ['watch'])
gulp.task('watch', ['setWatch', 'browserSync'], function () {
gulp.watch(config.markup.src, ['markup'])
})
gulp.task('setWatch', function () {
global.isWatching = true
})
gulp.task('browserSync', ['build', 'nodemon'], function () {
browserSync.init(null, {
proxy: 'http://localhost:5000',
port: 7000,
notify: true,
files: ['./build/**']
})
})
gulp.task('nodemon', function (cb) {
var called = false
return nodemon({
script: 'app.js',
ignore: [
'gulpfile.js',
'node_modules/**',
'build/**',
'src/**',
'test/**',
'.babelrc',
'package.json'
]
})
.on('start', function () {
if (!called) {
called = true
cb()
}
})
.on('restart', function () {
setTimeout(function () {
reload({ stream: false })
}, 1000)
})
})
gulp.task('build', ['browserify', 'markup'])
gulp.task('markup', function () {
return gulp.src(config.markup.src).pipe(gulp.dest(config.markup.dest))
})
// Browserify voodoo
gulp.task('browserify', function(callback) {
var bundleQueue = config.browserify.bundleConfigs.length
var browserifyThis = function(bundleConfig) {
var bundler = browserify({
// Required watchify args
cache: {}, packageCache: {}, fullPaths: false,
// Specify the entry point of your app
entries: bundleConfig.entries,
// Add file extentions to make optional in your requires
extensions: config.browserify.extensions,
// Enable source maps!
debug: config.browserify.debug
})
var bundle = function() {
// Log when bundling starts
bundleLogger.start(bundleConfig.outputName)
return bundler
.bundle()
// Report compile errors
.on('error', handleErrors)
// Use vinyl-source-stream to make the
// stream gulp compatible. Specifiy the
// desired output filename here.
.pipe(source(bundleConfig.outputName))
// Specify the output destination
.pipe(gulp.dest(bundleConfig.dest))
.on('end', reportFinished)
}
bundler.transform(babelify.configure({
stage: 1
}))
if (global.isWatching) {
// Wrap with watchify and rebundle on changes
bundler = watchify(bundler)
// Rebundle on update
bundler.on('update', bundle)
}
var reportFinished = function() {
// Log when bundling completes
bundleLogger.end(bundleConfig.outputName)
if (bundleQueue) {
bundleQueue--
if (bundleQueue === 0) {
// If queue is empty, tell gulp the task is complete.
// https://github.com/gulpjs/gulp/blob/master/docs/API.md#accept-a-callback
callback()
}
}
}
return bundle()
}
// Start bundling with Browserify for each bundleConfig specified
config.browserify.bundleConfigs.forEach(browserifyThis)
})