-
-
Save elgamine-dev/3d309dc165ebe6a43d7d to your computer and use it in GitHub Desktop.
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 gutil = require('gulp-util'); | |
var uglify = require('gulp-uglify'); | |
var jshint = require('gulp-jshint'); | |
var insert = require('gulp-insert'); | |
var livereload = require('gulp-livereload'); | |
var source = require('vinyl-source-stream'); | |
var buffer = require('vinyl-buffer'); | |
var watchify = require('watchify'); | |
var browserify = require('browserify'); | |
var scripts = 'src/js/*.js'; | |
gulp.task('default', ['watch']); | |
gulp.task('build', ['lint'], function() { | |
return browserify('./src/js/app.js').bundle() | |
.on('error', gutil.log.bind(gutil, 'Browserify Error')) | |
.pipe(source('bundle.min.js')) | |
.pipe(buffer()) | |
.pipe(uglify()) | |
.pipe(gulp.dest('.')); | |
}); | |
gulp.task('watch', function() { | |
var liveReloadScript = 'document.write(\'<script src="http://localhost:35729/livereload.js" id="livereload"></script>\');'; | |
watchify.args.debug = true; | |
var bundler = watchify(browserify('./src/js/app.js', watchify.args)); | |
livereload.listen(); | |
bundler.on('update', function() { | |
return bundler.bundle() | |
.on('error', gutil.log.bind(gutil, 'Browserify Error')) | |
.pipe(source('bundle.min.js')) | |
.pipe(buffer()) | |
.pipe(insert.prepend(liveReloadScript)) | |
.pipe(livereload()) | |
.pipe(gulp.dest('.')); | |
}); | |
}); | |
gulp.task('lint', function() { | |
return gulp.src(scripts) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('jshint-stylish')) | |
.pipe(jshint.reporter('fail')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment