Skip to content

Instantly share code, notes, and snippets.

@brunoventura
Last active March 10, 2016 17:43
Show Gist options
  • Save brunoventura/3e50defee144933366f6 to your computer and use it in GitHub Desktop.
Save brunoventura/3e50defee144933366f6 to your computer and use it in GitHub Desktop.
Gulp + Browserify + Babel + Error Handler = ❤️
const gulp = require('gulp');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const connect = require( 'gulp-connect' );
const path = {
files: './static/**/*',
entryFile: './static/lib/app.js',
build: './build/',
buildFile: 'bundle.js'
}
gulp.task('transpile', () => {
return browserify(path.entryFile)
.transform(babelify, {
presets: ["es2015", "react"],
plugins: ['babel-plugin-transform-decorators-legacy']
})
.bundle()
.on('error', function(err) {
console.error(err.stack);
this.emit('end');
})
.pipe(source(path.buildFile))
.pipe(gulp.dest(`${path.build}lib/`));
});
gulp.task('copyFiles', () => {
gulp.src([path.files, '!./static/lib/**/*'])
.pipe(gulp.dest(path.build));
});
gulp.task('watch', () => {
gulp.watch( path.files, [ 'files' ]);
});
gulp.task('files', ['copyFiles', 'transpile'], () => {
gulp.src(path.files).pipe(connect.reload());
});
gulp.task('connect', () => {
connect.server({
root: 'build',
livereload: true
});
});
gulp.task( 'serve', ['connect', 'watch']);
@brunoventura
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment