Skip to content

Instantly share code, notes, and snippets.

@michalochman
Last active May 19, 2021 22:11
Show Gist options
  • Save michalochman/d64360541a484e16817c to your computer and use it in GitHub Desktop.
Save michalochman/d64360541a484e16817c to your computer and use it in GitHub Desktop.

Revisions

  1. michalochman revised this gist Mar 4, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    /* jshint strict: false */
    /* globals require, console */
    var gulp = require('gulp');
    var exit = require('gulp-exit');

    var browserify = require('browserify');
    var watchify = require('watchify');
    @@ -13,6 +14,7 @@ var rename = require('gulp-rename');
    var uglify = require('gulp-uglify');
    var sourcemaps = require('gulp-sourcemaps');


    function compile(watch) {
    var bundler = watchify(browserify('./src/index.js', {debug: true}).transform(babelify, {
    // Use all of the ES2015 spec
  2. michalochman revised this gist Mar 4, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,6 @@ var babelify = require('babelify');

    var source = require('vinyl-source-stream');
    var buffer = require('vinyl-buffer');
    var merge = require('utils-merge');

    var rename = require('gulp-rename');
    var uglify = require('gulp-uglify');
    @@ -30,7 +29,6 @@ function compile(watch) {
    })
    .pipe(source('build.js'))
    .pipe(buffer())
    .pipe(gulp.dest('./build'))
    .pipe(rename('index.min.js'))
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(uglify())
  3. michalochman created this gist Mar 4, 2016.
    64 changes: 64 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    /* jshint strict: false */
    /* globals require, console */
    var gulp = require('gulp');

    var browserify = require('browserify');
    var watchify = require('watchify');
    var babelify = require('babelify');

    var source = require('vinyl-source-stream');
    var buffer = require('vinyl-buffer');
    var merge = require('utils-merge');

    var rename = require('gulp-rename');
    var uglify = require('gulp-uglify');
    var sourcemaps = require('gulp-sourcemaps');

    function compile(watch) {
    var bundler = watchify(browserify('./src/index.js', {debug: true}).transform(babelify, {
    // Use all of the ES2015 spec
    presets: ["es2015"],
    sourceMaps: true
    }));

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

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

    rebundle();
    } else {
    rebundle().pipe(exit());
    }
    }

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

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

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