-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
68 lines (57 loc) · 1.58 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
/*var gulp = require('gulp')
var react = require('gulp-react')
// transform jsx to js
gulp.task('transpile-js', function() {
return gulp.src('./src/*.jsx')
.pipe(react({harmony: true}))
.pipe(gulp.dest('./js'))
})
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('src/*.jsx', ['transpile-js']);
});
// Default Task
gulp.task('default', ['transpile-js', 'watch']);*/
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var sixtofiveify = require('6to5ify');
var reactify = require('reactify');
var watchify = require('watchify');
var browserify = require('browserify');
var browserSync = require('browser-sync');
//var uglify = require('gulp-uglify');
// Input file.
var bundler = watchify(browserify('./src/app.jsx', watchify.args));
// React JSX transform
bundler.transform(reactify);
// Babel, 6to5ify transform
bundler.transform(sixtofiveify);
// On updates recompile
bundler.on('update', bundle);
function bundle() {
return bundler.bundle()
.on('error', function (err) {
// on error log error
gutil.log(err.message);
browserSync.notify("Browserify Error!");
this.emit("end");
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./js'))
.pipe(browserSync.reload({stream: true, once: true}));
}
/**
* Gulp task alias
*/
gulp.task('bundle', function () {
return bundle();
});
/**
* First bundle, then serve from the current directory
*/
gulp.task('default', ['bundle'], function () {
browserSync({
server: "."
});
});