Skip to content

Commit

Permalink
feat(plug-in): add configure hook
Browse files Browse the repository at this point in the history
This commit removes the prebundle hook to configure and adds the
prebundle event that may be used to perform additional configuration.

This allows users to reliably hook into the bundling process in
browserify@7 times.

Closes #63
  • Loading branch information
nikku committed Dec 20, 2014
1 parent d465939 commit 7c2cc33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 11 additions & 4 deletions lib/bro.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function Bro(bundleFile) {
});

var browserifyOptions = _.extend({}, watchify.args, _.omit(bopts, [
'transform', 'plugin', 'prebundle', 'bundleDelay'
'transform', 'plugin', 'configure', 'bundleDelay'
]));

if ('exposeAll' in browserifyOptions) {
Expand Down Expand Up @@ -165,9 +165,9 @@ function Bro(bundleFile) {
w.transform.apply(w, t);
});

// test if we have a prebundle function
if (bopts.prebundle && typeof bopts.prebundle === 'function') {
bopts.prebundle(w);
// test if we have a configure function
if (bopts.configure && typeof bopts.configure === 'function') {
bopts.configure(w);
}

// register rebuild bundle on change
Expand Down Expand Up @@ -236,6 +236,13 @@ function Bro(bundleFile) {
});
}

// fire this small little event so that
// parties may take part in the bundling process
// in the configure hook

w.emit('prebundle');


log.debug('bundling');

files.forEach(function(f) {
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions test/spec/pluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,19 @@ describe('bro', function() {
});


it('should support prebundle in the options', function(done) {
it('should support configure hook in the options', function(done) {

// given
var plugin = createPlugin({
browserify: {
prebundle: function(bundle) {
configure: function(bundle) {
bundle.external('foobar');
}
}
});

var bundleFile = createFile(bundle.location);
var testFile = createFile('test/fixtures/prebundle.js');
var testFile = createFile('test/fixtures/configure.js');

// when
plugin.preprocess(bundleFile, [ testFile ], function() {
Expand Down Expand Up @@ -618,7 +618,7 @@ describe('bro', function() {
browserify: {
transform: [ 'brfs' ],
// Hook into bundler/pipeline events for success/error
prebundle: function(bundle) {
configure: function(bundle) {
// After first bundle
bundle.once('bundled', function (err) {
// Fail if there was an error
Expand Down Expand Up @@ -650,7 +650,7 @@ describe('bro', function() {
browserify: {
plugin: [ ['tsify', { removeComments: true } ] ],
// Hook into bundler/pipeline events for success/error
prebundle: function(bundle) {
configure: function(bundle) {
// After first bundle
bundle.once('bundled', function (err) {
// Fail if there was an error
Expand Down

0 comments on commit 7c2cc33

Please sign in to comment.