browserify transform to replace require calls to custom browser globals
This transform will turn this:
var win = ;var doc = ;
var win = globalwindow;var doc = globaldocument;
So your code works well once it runs in the browser.
npm i --save-dev shimixify
// this is the hash of shims that will be matched against the// calls to require. For example calling// require('jQuery') ==> will be replaced by ==> (global.jQuery);// browserify injects a global variable that is a reference to the window object// technically you can also use jQuery directly without using the `global` notationvar shims =window: 'global.window'jQuery: 'global.jQuery'chrome: 'global.chrome'screen: 'global.screen'document: 'global.document'Worker: 'global.Worker'Promise: 'global.Promise'self: 'global.self'react: 'global.React';var shimify = ;var b = ;b;b;b;
NOTE: accessing window, document or other globals from a module will work, but it makes explicit that you're accessing a global. Using this transform will make it easier to have code that is easily testable using tools like proxiquerify, to replace those dependencies during unit testing.
var proxyquire = ;var mockWindow = ;// this will replace calls to require('window') with a mocked instance// in order to make the unit tests for this module// no more globals and your code is not easier to test!var myModule = ;