2015-12-06 2 views
1

У меня есть эта Bundler в Gulpfile.js, он хорошо работает:Выведите уменьшенная версия и не уменьшенная версия с Глоток

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

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

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

    rebundle(); 
}; 

это дает мне: arli.js и arli.js.map

но при попытке уродовать его следующим образом:

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

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

    return gulp.src('./dist/lib.js') 
     .pipe(rename('lib.min.js')) 
     .pipe(sourcemaps.init()) 
     .pipe(uglify({ 
     preserveComments: 'license', 
     })) 
     .pipe(sourcemaps.write('./')) 
     .pipe(gulp.dest('./dist/')); 
    }; 

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

    rebundle(); 
}; 

это дает мне те же два файла, но если я повторить задачу он даст мне lib.min.js и lib.min.js.map тоже, потому что в первый раз lib.js не существовало.

Я пробовал с run-sequence, но это тоже самое.

ответ

1

Вы можете использовать обратный вызов end?

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

    var rebundle =() => { 
    bundler.bundle() 
     .on('error', function(err) { console.error(err); this.emit('end'); }) 
     .pipe(source(lib.js)) 
     .pipe(buffer()) 
     .pipe(sourcemaps.init({ loadMaps: true })) 
     .pipe(sourcemaps.write('./')) 
     .pipe(gulp.dest('./dist/')).on('end', function() { 
     gulp.src('./dist/lib.js') 
      .pipe(rename('lib.min.js')) 
      .pipe(sourcemaps.init()) 
      .pipe(uglify({ 
      preserveComments: 'license', 
      })) 
      .pipe(sourcemaps.write('./')) 
      .pipe(gulp.dest('./dist/')).on('end', function() { 
      done(); 
      }); 
     }); 
    }; 

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

    rebundle(); 
}; 
+0

Спасибо, я попробую – elkebirmed

Смежные вопросы