Skip to content

Instantly share code, notes, and snippets.

@abdulhannanali
Created January 7, 2016 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulhannanali/4249c21d7dccea33f6b9 to your computer and use it in GitHub Desktop.
Save abdulhannanali/4249c21d7dccea33f6b9 to your computer and use it in GitHub Desktop.
Gulp, Browserify, Babelify and React gulpfile. Don't use Watchify instead use gulp.watch. A personal tip. Watchify gives me problems
var gulp = require('gulp')
var browserify = require('browserify')
var watchify = require('watchify')
var babelify = require('babelify')
var plumber = require('gulp-plumber')
var buffer = require("vinyl-buffer")
var source = require("vinyl-source-stream")
var sourcemaps = require("gulp-sourcemaps")
var uglify = require("gulp-uglify")
var someConfigOptions = {
MAIN_FILE : "src/index.js"
}
gulp.task("browserify", function () {
var bundler = browserify({
entries: ["./src/index.js"],
debug:true,
cache: {}, packageCache: {}, fullPaths: true
})
.transform(babelify, {})
function bundle() {
console.log("bundling <<<<<<")
bundler.bundle()
.pipe(plumber())
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps:true}))
// .pipe(uglify())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./build/"))
bundler.on("error", function (error) {
console.log(error)
})
}
bundle()
})
gulp.task("watch", function () {
console.log("Gulp is now watching for changes in ./src/")
gulp.watch([
"./src/**/*.js",
"./src/*.js"
], ["browserify"])
})
gulp.task('default', [
'browserify',
"watch"
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment