Last active
August 29, 2015 14:13
-
-
Save vojd/a2d277bc161a2674aeaa to your computer and use it in GitHub Desktop.
Gulp, browserify, reactify, notify and watchify for coffeescript
This file contains 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
# Original https://gist.github.com/Sigmus/9253068 | |
source = require 'vinyl-source-stream' | |
gulp = require 'gulp' | |
gutil = require 'gulp-util' | |
browserify = require 'browserify' | |
reactify = require 'reactify' | |
watchify = require 'watchify' | |
notify = require 'gulp-notify' | |
paths = | |
mainFile: 'app.js' | |
src: './src/' | |
build: './build/' | |
dist: './dist/' | |
# Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/ | |
buildScript = (file, watch) -> | |
rebundle = -> | |
stream = bundler.bundle() | |
stream.on("error", notify.onError( | |
title: "Compile Error" | |
message: "<%= error.message %>" | |
)).pipe(source(file)).pipe gulp.dest(paths.build) | |
props = watchify.args | |
props.entries = [paths.src + file] | |
props.debug = true | |
bundler = (if watch then watchify(browserify(props)) else browserify(props)) | |
bundler.transform reactify | |
bundler.on "update", -> | |
rebundle() | |
gutil.log "Rebundled..." | |
return | |
rebundle() | |
gulp.task "build", -> | |
buildScript paths.mainFile, false | |
gulp.task "default", ["build"], -> | |
buildScript paths.mainFile, true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment