forked from SteveVitali/react-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
41 lines (35 loc) · 1.15 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
var resolutions = require('browserify-resolutions');
var uglify = require('gulp-uglify');
function compile(watch) {
var bundler = watchify(
browserify('./src/FormGenerator.jsx', { debug: true })
.plugin(resolutions, ['react'])
.transform(babel)
);
function rebundle() {
var start = Date.now();
bundler.bundle()
.on('error', function(err) {
console.error(err); this.emit('end');
})
.pipe(source('FormGenerator.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
console.log('Updated in', (Date.now() - start) + 'ms');
}
watch && bundler.on('update', rebundle);
rebundle();
}
gulp.task('build', function() { return compile(); });
gulp.task('watch', function() { return compile(true); });
gulp.task('default', ['watch']);