-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
43 lines (38 loc) · 1.51 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
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
gulp.task('browserify', function() {
var bundler = browserify({
entries: ['client/app.jsx'], // Only need initial file, browserify finds the deps
transform: [reactify], // We want to convert JSX to normal javascript
debug: true, // Gives us sourcemapping
cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
});
function onError(err) {
console.log(err);
}
var watcher = watchify(bundler);
return watcher
.on('update', function() { // When any files update
console.log('Updating...');
var updateStart = Date.now();
watcher
.bundle() // Create new bundle that uses the cache for high performance
.on('error', onError)
.pipe(source('main.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('public/js/'));
console.log('Updated.', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.on('error', onError)
.pipe(source('main.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('public/js/'));
});
gulp.task('default', ['browserify']);