Created
November 12, 2015 05:54
-
-
Save terranmoccasin/afe73f24bbb9151b2184 to your computer and use it in GitHub Desktop.
gulpfile destroying my life (the update task only fires once too...)
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
var gulp = require('gulp'); | |
var browserify = require('browserify'); | |
var babelify = require('babelify'); | |
var watchify = require('watchify'); | |
var fs = require('fs'); | |
var envify = require('envify/custom'); | |
var source = require('vinyl-source-stream'); | |
var sass = require('gulp-sass'); | |
var concatCss = require('gulp-concat-css'); | |
var gutil = require('gulp-util'); | |
var mainFileOpts = { | |
input: ['./js/main.js'], | |
output: 'main.js', | |
destination: './dist/js' | |
}; | |
gulp.task('js', function() { | |
createBundle(mainFileOpts); | |
}); | |
function createBundle(file) { | |
var b = browserify({ | |
entries: file.input, | |
fileInfo: file, | |
debug: true, | |
cache: {}, | |
packageCache: {}, | |
plugin: [watchify], | |
transform: [ | |
babelify, | |
envify({NODE_ENV: process.env.NODE_ENV}) | |
] | |
}); | |
b.on('update', function(e) { | |
gutil.log('update'); | |
if(typeof e === 'object') { | |
gutil.log(gutil.colors.cyan('Changes detected on: ')); | |
for (var i = 0, len = e.length; i < len; i ++) { | |
gutil.log(gutil.colors.magenta(e[i])); | |
} | |
} | |
// build(this); | |
}); | |
b.on('log', function(msg) { | |
gutil.log(msg); | |
}); | |
build(b); | |
} | |
function build(bundle) { | |
gutil.log('Building...'); | |
return bundle.bundle() | |
.on('error', errorHandler) | |
.pipe(fs.createWriteStream('./dist/js/main.js')); | |
} | |
// Handle the error | |
function errorHandler (error) { | |
console.log(error.toString()); | |
this.emit('end'); | |
} | |
gulp.task('sass', function() { | |
gulp.src('./scss/**/*.scss') | |
.pipe(sass({includePaths: require('node-bourbon').includePaths})).on('error', errorHandler) | |
.pipe(concatCss('main.css')) | |
.pipe(gulp.dest('./dist/css')); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('./scss/**/*.scss', ['sass']); | |
}); | |
gulp.task('default', ['js', 'sass', 'watch']).on('error', errorHandler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment