I have a library which is to run in the browser as well as on the server. This library is dependent on Needle which makes XMLHttpRequests requests if used in the browser. This library is to use the bundled browserified library on the front-end and uses the regular ES6 code in Node.
So there are two sets of code here, dist/vendor.min.js for the browser to use, and lib/index.js for node to use. In the entry point for my library
index.js
'use strict';
// In browsers, load the bundled version
module.exports = process.browser ? require('./dist/vendor.min.js') : require('./lib/index.js}');
package.json
{
"main": "index.js"
}
This solution works fine until I decide to uglify the front-end code. The application that is using this library is uglifying all of the 3rd party libraries in the production environment and whats going on here is uglify is also trying to uglify the node code which is non transpiled ES6 javascript.
Is there a better way to conditionally load these libraries?