-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
48 lines (43 loc) · 1.57 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
const gulp = require('gulp'); //skeleton, responsible for build process
const gutil = require('gulp-util'); //responsible for logging build process
const source= require('vinyl-source-stream'); //"throwing" text files from one step to another
const browserify = require('browserify'); //figures out dependencies for load order
const watchify = require('watchify'); //automatically re-runs gulp file whenever code changes
const reactify = require('reactify'); //works with browserify to convert jsx to js
const server = require('gulp-server-livereload');
const concat = require('gulp-concat');
var bundler = watchify(browserify({
entries: ['./src/app.jsx'],
transform: [reactify],
extensions: ['.jsx'],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
}));
function bundle() {
return bundler
.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error')) //event handler
.pipe(source('main.js')) //after bundle is done, put it into main.js
.pipe(gulp.dest('./')); //put main.js into the cwd
};
bundler.on('update', bundle) //when we make a change, rebuild!
gulp.task('build', bundle);
gulp.task('serve', function(done) {
gulp.src('')
.pipe(server({
livereload: {
enable: true,
filter: function(filePath, cb) {
if(/main.js/.test(filePath)) {
cb(true)
} else if(/style.css/.test(filePath)){
cb(true)
}
}
},
open: true
}));
});
gulp.task('default', ['build', 'serve']);