Last active
March 10, 2016 17:43
-
-
Save brunoventura/3e50defee144933366f6 to your computer and use it in GitHub Desktop.
Gulp + Browserify + Babel + Error Handler = ❤️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/brunoventura/3e50defee144933366f6#file-gulpfile-js-L21
Normal function used here to maintain the scope