Closed crawlregister closed 8 years ago
I have found a workaround for this behavior using the configure
function & prebundle
event in the config block:
browserify: {
config:{
watchify: {
poll: true
}
},
configure: function(bundle) {
bundle.on('prebundle', function() {
bundle.require('./path/to/appConfig', {expose: 'appConfig'});
});
}
}
You may be able to execute bundle.require('moment')
with or without the expose
setting.
Please let me know if that helps
Thanks @chrisdeely I will give it a try.
Another potential solution is build the external requires into another bundle and make sure it is ready before running karma test.
Browserify has some strange behavior around externals and stuff.
The working way of consistently exposing moment
from outside the bundle is:
...
browserify: {
configure: function(bundle) {
bundle.require('moment');
}
}
I am happy to accept PRs if you would like to contribute an improvement here.
I created a simple example to show the problem I encountered. There is an external module must be required at creating the bundle with browserify.
My karma.conf.js is like this:
There is an external require specified as require: ['moment'] The first time run karma start, the moment module is included in the bundle correctly. Then I edit the main.js and save, which will trigger rebundle. But in the new bundle, moment module is missing from the new bundle.