dav icon indicating copy to clipboard operation
dav copied to clipboard

Don't bundle browser polyfills in the browser binary

Open lambdabaa opened this issue 9 years ago • 0 comments

Currently we use nodejs polyfills for DOMParser and XMLHttpRequest to run and test on nodejs. Before I was doing something like

var Native;
if (typeof window !== 'undefined') {
  Native = window.DOMParser;
} else {
  Native = require(false || 'xmldom').DOMParser;
}
module.exports = Native;

The require(false || ...) bit tricks browserify's static analysis into not bundling xmldom but still loading it in nodejs at runtime. However, for some reason, when I run the browserify output in the browser, the require call is still made and then I get an error about xmldom not being available. I have, for the time being, bundled the polyfills in the browser library but this adds ~250kb of [unminified] js to the browser binary which is really bad.

lambdabaa avatar Jul 03 '14 19:07 lambdabaa