Skip to content

suggesting a cleaner way#924

Merged
yocontra merged 3 commits intogulpjs:masterfrom
asfktz:patch-1
Feb 27, 2015
Merged

suggesting a cleaner way#924
yocontra merged 3 commits intogulpjs:masterfrom
asfktz:patch-1

Conversation

@asfktz
Copy link
Copy Markdown
Contributor

@asfktz asfktz commented Feb 24, 2015

@yocontra
Copy link
Copy Markdown
Member

This is going to create a bundle for every js file in the folder, I don't think that is what users are expecting

@asfktz
Copy link
Copy Markdown
Contributor Author

asfktz commented Feb 24, 2015

Absolutely right. Fixed.

@yocontra
Copy link
Copy Markdown
Member

@phated Thoughts? This is a lot cleaner IMO

@phated
Copy link
Copy Markdown
Member

phated commented Feb 24, 2015

👍 I love vinyl-transform. It's like @hughsk's successor to the other vinyl-* modules he made. Even buffers by default. I think this should be the defacto way we promote using existing modules. Can you add a note to the top referencing the blog post?

@yocontra
Copy link
Copy Markdown
Member

Cool I'm +1 to merge this. If you see any other docs using vinyl-buffer feel free to update those as well!

@asfktz
Copy link
Copy Markdown
Contributor Author

asfktz commented Feb 27, 2015

I tried to make it work with the watchify example but with not success, can't figure way..

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var transform = require('vinyl-transform');
var watchify = require('watchify');
var browserify = require('browserify');

var bundler = watchify(browserify('./src/app.js', watchify.args));
// add any other browserify options or transforms here
//bundler.transform('brfs');

gulp.task('js', bundle); // so you can run `gulp js` to build the file
bundler.on('update', function (aa) {
    console.log(aa);
    bundle();
}); // on any dep update, runs the bundler

function bundle() {
    var bundled = transform(function () {
        return bundler.bundle();
    });

    return bundled
        // log errors if they happen
        .on('error', gutil.log.bind(gutil, 'Browserify Error'))
        .pipe(source('bundle.js'))
        // optional, remove if you dont want sourcemaps
        .pipe(buffer())
        .pipe(sourcemaps.init({
            loadMaps: true
        }))
            .pipe($.react({harmony: true}))
            //.pipe($.uglify())
        // loads map from browserify file
        .pipe(sourcemaps.write('./')) // writes .map file
        //
        .pipe(gulp.dest('./dist'));
}

yocontra pushed a commit that referenced this pull request Feb 27, 2015
suggesting a cleaner way
@yocontra yocontra merged commit 5c8ee6d into gulpjs:master Feb 27, 2015
@moimikey
Copy link
Copy Markdown

moimikey commented Mar 2, 2015

@contra @asfktz that getBundleName named func should probably get 86ed too.

@callumacrae
Copy link
Copy Markdown
Member

Doesn't this read the JS file from disk twice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants