forked from civictechdc/dc-campaign-finance-watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (63 loc) · 1.69 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
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var concat = require('gulp-concat');
var gutil = require('gulp-util');
var browserSync = require('browser-sync');
var nodemon = require('gulp-nodemon');
var path = require('path');
var fs = require('fs');
var watchifyOpts = { poll: true }
var bundler = watchify(browserify('./client/app.jsx', watchify.args), watchifyOpts);
bundler.transform(babelify);
bundler.on('update', function(){
gutil.log('file changed, browserify it');
bundle();
});
function bundle() {
gutil.log('bundling up the js goodness');
return bundler.bundle()
.on('error', function(err){
gutil.log(err.message);
browserSync.notify('Browserify Error!');
this.emit('end');
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./client/js/dist'))
.pipe(browserSync.stream());
}
gulp.task('create-config', function(done){
fs.writeFile('client/config.json', JSON.stringify({
env: gutil.env.env
}), done);
});
gulp.task('bundle', ['create-config'], function() {
bundle();
});
gulp.task('nodemon', function(){
nodemon({
script: './app.js',
ext: 'js',
ignore: ['client/**/*.*']
})
.on('restart', function(){
gutil.log('restarting the process');
});
});
gulp.task('serve-dev', ['browsersync']);
gulp.task('browsersync', ['bundle', 'nodemon'], function() {
browserSync({
files: ['client/**/*.jsx'],
open: 'local',
server: 'client',
ui: {
port: '4000'
},
port: '3001'
});
});