Last active
December 18, 2015 12:30
-
-
Save stabenfeldt/644dfddac942d61db5e4 to your computer and use it in GitHub Desktop.
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
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var source = require('vinyl-source-stream'); | |
var browserify = require('browserify'); | |
var watchify = require('watchify'); | |
var reactify = require('reactify'); | |
var notifier = require('node-notifier'); | |
var server = require('gulp-server-livereload'); | |
var concat = require('gulp-concat'); | |
var sass = require('gulp-sass'); | |
var watch = require('gulp-watch'); | |
var notify = function(error) { | |
var message = 'In: '; | |
var title = 'Error: '; | |
if(error.description) { | |
title += error.description; | |
} else if (error.message) { | |
title += error.message; | |
} | |
if(error.filename) { | |
var file = error.filename.split('/'); | |
message += file[file.length-1]; | |
} | |
if(error.lineNumber) { | |
message += '\nOn Line: ' + error.lineNumber; | |
} | |
notifier.notify({title: title, message: message}); | |
}; | |
var bundler = watchify(browserify({ | |
entries: ['./src/app.jsx'], | |
transform: [reactify], | |
extensions: ['.jsx'], | |
debug: true, | |
cache: {}, | |
packageCache: {}, | |
fullPaths: true | |
})); | |
function bundle() { | |
return bundler | |
.bundle() | |
.on('error', notify) | |
.pipe(source('main.js')) | |
.pipe(gulp.dest('./')) | |
} | |
bundler.on('update', bundle) | |
gulp.task('build', function() { | |
bundle() | |
}); | |
gulp.task('serve', function(done) { | |
gulp.src('') | |
.pipe(server({ | |
livereload: { | |
enable: true, | |
filter: function(filePath, cb) { | |
if(/main.js/.test(filePath)) { | |
cb(true) | |
} else if(/style.css/.test(filePath)){ | |
cb(true) | |
} | |
} | |
}, | |
open: true | |
})); | |
}); | |
gulp.task('sass', function () { | |
gulp.src('./sass/**/*.scss') | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(concat('style.css')) | |
.pipe(gulp.dest('./')); | |
}); | |
gulp.task('default', ['build', 'serve', 'sass', 'watch']); | |
gulp.task('watch', function () { | |
gulp.watch('./sass/**/*.scss', ['sass']); | |
}); | |
/* | |
* | |
* | |
package.json | |
{ | |
"name": "react-starter", | |
"version": "1.0.0", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"browserify": "^9.0.3", | |
"gulp": "^3.8.11", | |
"gulp-concat": "^2.5.2", | |
"gulp-react": "^3.0.1", | |
"gulp-sass": "^2.0.1", | |
"gulp-server-livereload": "^1.3.0", | |
"gulp-util": "^3.0.4", | |
"gulp-watch": "^4.2.4", | |
"lodash": "^3.10.0", | |
"node-notifier": "^4.2.1", | |
"react": "^0.13.3", | |
"react-router": "1.0.0-beta2", | |
"reactify": "^1.1.0", | |
"reflux": "^0.2.8", | |
"vinyl-source-stream": "^1.1.0", | |
"watchify": "^2.4.0", | |
"whatwg-fetch": "^0.9.0" | |
}, | |
"devDependencies": {} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment