Skip to content

Instantly share code, notes, and snippets.

@gregberge
Created March 4, 2015 12:42
Show Gist options
  • Save gregberge/a834f55ba665a6b616b6 to your computer and use it in GitHub Desktop.
Save gregberge/a834f55ba665a6b616b6 to your computer and use it in GitHub Desktop.
Watchify, browserify gulp.
var gulp = require('gulp');
var gutil = require('gulp-util');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var browserSync = require('browser-sync');
var sass = require('gulp-ruby-sass');
var filter = require('gulp-filter');
gulp.task('browserify', function () {
var bundler = browserify('./src/main.js');
bundler.transform('debowerify');
bundler.transform('brfs');
return bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('markers.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./build'));
});
gulp.task('watchify', function() {
watchify.args.debug = true;
var bundler = watchify(browserify('./src/main.js', watchify.args));
bundler.transform('debowerify');
bundler.transform('brfs');
bundler.on('update', rebundle);
bundler.on('log', gutil.log.bind(gutil));
function rebundle() {
return bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('markers.js'))
.pipe(gulp.dest('./build'));
}
return rebundle();
});
gulp.task('browsersync', function() {
browserSync({
open: false,
server: {
baseDir: './'
}
});
});
gulp.task('sass', function () {
return gulp.src('sass/miwo-markers.scss')
.pipe(sass({
require: ['./sass/functions/url64.rb']
}))
.on('error', gutil.log.bind(gutil, 'Sass Error'))
.pipe(gulp.dest('build'))
.pipe(filter('**/*.css'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('watch-sass', function () {
return gulp.watch('sass/**/*.scss', ['sass']);
});
gulp.task('copy-fonts', function () {
return gulp.src('fonts/**/*')
.pipe(gulp.dest('build/'));
});
gulp.task('default', ['copy-fonts', 'sass', 'watch-sass', 'watchify', 'browsersync']);
gulp.task('build', ['copy-fonts', 'sass', 'browserify']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment