Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following function for bundling my JavaScript modules:

function buildScript( entryPoint, doDebug ) {
    return browserify( {
        entries: [ './dev-res/js/' + entryPoint ],
        extensions: [ '.js' ],
        debug: doDebug ? true : false
    } )
        .transform( babelify, {
            presets: [ "es2015", "react", "stage-0" ] } )
        .bundle()
        .on( 'error', handleErrors )
        .pipe( source( entryPoint ) )
        .pipe( buffer() )
        .pipe( uglify() )
        .pipe( gulp.dest( './res/js/' ) );
}

I want to trigger these two lines

.pipe( buffer() )
.pipe( uglify() )

only when doDebug is not true. This means I should declare a variable to remove the chained calls. I tried saying

var module = browserify( {
    entries: [ './dev-res/js/' + entryPoint ],
    extensions: [ '.js' ],
    debug: doDebug ? true : false
} );

But then I get something like browserify has no method pipe, so this is my problem: I don't know what to save in that variable. I admit that I don't really have a deep understanding of how browserify define their code and how it actually works, but I just need to get this method do what I want.

share|improve this question

put on hold as off-topic by 200_success May 5 at 20:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Why is this off-topic? THis is 100% code review. – Victor May 5 at 20:33
2  
It returns errors and it seems like you're asking how to fix that error. – Zacharee1 May 5 at 22:42
    
Check out gulpif – elclanrs May 6 at 0:54

Browse other questions tagged or ask your own question.