Skip to content

Instantly share code, notes, and snippets.

@josephdburdick
Forked from danharper/gulpfile.js
Last active September 21, 2015 22:42
Show Gist options
  • Save josephdburdick/2ed5b50aaee712d9d70c to your computer and use it in GitHub Desktop.
Save josephdburdick/2ed5b50aaee712d9d70c to your computer and use it in GitHub Desktop.

Revisions

  1. @danharper danharper revised this gist Feb 18, 2015. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -7,30 +7,30 @@ var watchify = require('watchify');
    var babel = require('babelify');

    function compile(watch) {
    var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
    var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));

    function rebundle() {
    bundler.bundle()
    .on('error', function(err) { console.error(err); this.emit('end'); })
    .pipe(source('build.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({ loadMaps: true }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./build'));
    }
    function rebundle() {
    bundler.bundle()
    .on('error', function(err) { console.error(err); this.emit('end'); })
    .pipe(source('build.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({ loadMaps: true }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./build'));
    }

    if (watch) {
    bundler.on('update', function() {
    console.log('-> bundling...');
    rebundle();
    });
    }
    if (watch) {
    bundler.on('update', function() {
    console.log('-> bundling...');
    rebundle();
    });
    }

    rebundle();
    rebundle();
    }

    function watch() {
    return compile(true);
    return compile(true);
    };

    gulp.task('build', function() { return compile(); });
  2. @danharper danharper created this gist Feb 18, 2015.
    39 changes: 39 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    var gulp = require('gulp');
    var sourcemaps = require('gulp-sourcemaps');
    var source = require('vinyl-source-stream');
    var buffer = require('vinyl-buffer');
    var browserify = require('browserify');
    var watchify = require('watchify');
    var babel = require('babelify');

    function compile(watch) {
    var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));

    function rebundle() {
    bundler.bundle()
    .on('error', function(err) { console.error(err); this.emit('end'); })
    .pipe(source('build.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({ loadMaps: true }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./build'));
    }

    if (watch) {
    bundler.on('update', function() {
    console.log('-> bundling...');
    rebundle();
    });
    }

    rebundle();
    }

    function watch() {
    return compile(true);
    };

    gulp.task('build', function() { return compile(); });
    gulp.task('watch', function() { return watch(); });

    gulp.task('default', ['watch']);