Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Last active November 15, 2017 11:55
Show Gist options
  • Select an option

  • Save Sigmus/9253068 to your computer and use it in GitHub Desktop.

Select an option

Save Sigmus/9253068 to your computer and use it in GitHub Desktop.

Revisions

  1. Sigmus revised this gist Jul 9, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@ var reactify = require('reactify');
    var watchify = require('watchify');
    var notify = require("gulp-notify");

    var scriptDir = './scripts';
    var buildDir = './build/';
    var scriptsDir = './scripts';
    var buildDir = './build';


    function handleErrors() {
    @@ -22,14 +22,14 @@ function handleErrors() {

    // Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
    function buildScript(file, watch) {
    var props = {entries: ['./scripts/' + file]};
    var props = {entries: [scriptsDir + '/' + file]};
    var bundler = watch ? watchify(props) : browserify(props);
    bundler.transform(reactify);
    function rebundle() {
    var stream = bundler.bundle({debug: true});
    return stream.on('error', handleErrors)
    .pipe(source(file))
    .pipe(gulp.dest('./build/'));
    .pipe(gulp.dest(buildDir + '/'));
    }
    bundler.on('update', function() {
    rebundle();
  2. Sigmus revised this gist Jul 9, 2014. 2 changed files with 54 additions and 27 deletions.
    59 changes: 41 additions & 18 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,49 @@
    var source = require('vinyl-source-stream');
    var gulp = require('gulp');
    var gutil = require('gulp-util');
    var browserify = require('gulp-browserify');
    var browserify = require('browserify');
    var reactify = require('reactify');
    var watchify = require('watchify');
    var notify = require("gulp-notify");

    gulp.task('build', function() {
    gulp.src('./scripts/main.js', {read: false})
    .pipe(browserify({
    transform: ['reactify'], // implies that the module 'reactify' is installed
    extensions: ['.jsx'] // you can omit the extension when requiring
    }))
    .on('prebundle', function(bundle) {
    // any module requiring underscore will get lodash instead (e.g. Backbone)
    bundle.require('lodash', {expose: 'underscore'});
    })
    .on('error', gutil.log)
    .on('error', gutil.beep)
    .pipe(gulp.dest('./build/'))
    });
    var scriptDir = './scripts';
    var buildDir = './build/';


    function handleErrors() {
    var args = Array.prototype.slice.call(arguments);
    notify.onError({
    title: "Compile Error",
    message: "<%= error.message %>"
    }).apply(this, args);
    this.emit('end'); // Keep gulp from hanging on this task
    }


    gulp.task('watch', function() {
    gulp.watch('./scripts/**/*.js', ['build']);
    // Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
    function buildScript(file, watch) {
    var props = {entries: ['./scripts/' + file]};
    var bundler = watch ? watchify(props) : browserify(props);
    bundler.transform(reactify);
    function rebundle() {
    var stream = bundler.bundle({debug: true});
    return stream.on('error', handleErrors)
    .pipe(source(file))
    .pipe(gulp.dest('./build/'));
    }
    bundler.on('update', function() {
    rebundle();
    gutil.log('Rebundle...');
    });
    return rebundle();
    }


    gulp.task('build', function() {
    return buildScript('main.js', false);
    });


    gulp.task('default', ['build', 'watch'])
    gulp.task('default', ['build'], function() {
    return buildScript('main.js', true);
    });
    22 changes: 13 additions & 9 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,22 @@
    {
    "name": "gulp example",
    "name": "scripts",
    "version": "0.0.0",
    "description": "",
    "main": "gulpfile.js",
    "devDependencies": {
    "envify": "~1.2.1",
    "react": "~0.10.0",
    "browserify": "~4.2.0",
    "gulp": "~3.8.5",
    "gulp-notify": "~1.4.0",
    "gulp-util": "~2.2.19",
    "reactify": "~0.13.1",
    "vinyl-source-stream": "~0.1.1",
    "watchify": "~0.10.2"
    },
    "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "",
    "license": "BSD-2-Clause",
    "devDependencies": {
    "gulp": "~3.5.2",
    "gulp-util": "~2.2.14",
    "gulp-browserify": "~0.4.6",
    "reactify": "~0.8.1",
    "lodash": "~2.4.1"
    }
    "license": "BSD-2-Clause"
    }
  3. Sigmus revised this gist Mar 22, 2014. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,12 @@ var browserify = require('gulp-browserify');
    gulp.task('build', function() {
    gulp.src('./scripts/main.js', {read: false})
    .pipe(browserify({
    transform: ['reactify'],
    extensions: ['.jsx']
    transform: ['reactify'], // implies that the module 'reactify' is installed
    extensions: ['.jsx'] // you can omit the extension when requiring
    }))
    .on('prebundle', function(bundle) {
    bundle.require('lodash', {expose: 'underscore'});
    // any module requiring underscore will get lodash instead (e.g. Backbone)
    bundle.require('lodash', {expose: 'underscore'});
    })
    .on('error', gutil.log)
    .on('error', gutil.beep)
    @@ -18,7 +19,7 @@ gulp.task('build', function() {


    gulp.task('watch', function() {
    gulp.watch('./scripts/**', ['build']);
    gulp.watch('./scripts/**/*.js', ['build']);
    });


  4. Sigmus revised this gist Mar 6, 2014. 2 changed files with 7 additions and 1 deletion.
    5 changes: 5 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -8,13 +8,18 @@ gulp.task('build', function() {
    transform: ['reactify'],
    extensions: ['.jsx']
    }))
    .on('prebundle', function(bundle) {
    bundle.require('lodash', {expose: 'underscore'});
    })
    .on('error', gutil.log)
    .on('error', gutil.beep)
    .pipe(gulp.dest('./build/'))
    });


    gulp.task('watch', function() {
    gulp.watch('./scripts/**', ['build']);
    });


    gulp.task('default', ['build', 'watch'])
    3 changes: 2 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@
    "gulp": "~3.5.2",
    "gulp-util": "~2.2.14",
    "gulp-browserify": "~0.4.6",
    "reactify": "~0.8.1"
    "reactify": "~0.8.1",
    "lodash": "~2.4.1"
    }
    }
  5. Sigmus revised this gist Feb 27, 2014. 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
    @@ -13,10 +13,8 @@ gulp.task('build', function() {
    .pipe(gulp.dest('./build/'))
    });


    gulp.task('watch', function() {
    gulp.watch('./scripts/**', ['build']);
    });


    gulp.task('default', ['build', 'watch'])
  6. Sigmus revised this gist Feb 27, 2014. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    {
    "name": "gulp example",
    "version": "0.0.0",
    "description": "",
    "main": "gulpfile.js",
    "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "",
    "license": "BSD-2-Clause",
    "devDependencies": {
    "gulp": "~3.5.2",
    "gulp-util": "~2.2.14",
    "gulp-browserify": "~0.4.6",
    "reactify": "~0.8.1"
    }
    }
  7. Sigmus created this gist Feb 27, 2014.
    22 changes: 22 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    var gulp = require('gulp');
    var gutil = require('gulp-util');
    var browserify = require('gulp-browserify');

    gulp.task('build', function() {
    gulp.src('./scripts/main.js', {read: false})
    .pipe(browserify({
    transform: ['reactify'],
    extensions: ['.jsx']
    }))
    .on('error', gutil.log)
    .on('error', gutil.beep)
    .pipe(gulp.dest('./build/'))
    });


    gulp.task('watch', function() {
    gulp.watch('./scripts/**', ['build']);
    });


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