'use strict'; const gulp = require('gulp'); const browserify = require('browserify'); const rename = require('gulp-rename'); const babelify = require( 'babelify'); const buffer = require('vinyl-buffer'); const sourcemaps = require('gulp-sourcemaps'); const source = require('vinyl-source-stream'); const uglify = require('gulp-uglify-es').default; function bundle_js(bundler) { return bundler.bundle() // .on('error', map_error) .pipe(source('app.js')) .pipe(buffer()) .pipe(rename('bundle.js')) .pipe(sourcemaps.init({ 'loadMaps': true })) // capture sourcemaps from transforms .pipe(uglify()) .pipe(sourcemaps.write('.')) .pipe(gulp.dest('./src/react')); } gulp.task('bundleReact', function () { const bundler = browserify('./src/react/js/app.js', { 'debug': true }).transform(babelify, { 'presets': ['es2015', 'react'] }); return bundle_js(bundler); }); gulp.task('buildReact', ['bundleReact'], function() { gulp.watch('src/react/js/**/*.js', ['bundleReact']); });