brunch/brunch — pull request #584 by benjamincox (2013-05-31 23:46:56+00:00)
Title: Eliminates IE 8 stack overflow

Internet Explorer 8 has a limitation whereby a given call stack for a function that's attached to 'window' can only contain that function at most 13 times before IE gives a "Stack overflow at line 0" error.

We ran into this with Brunch because require() is hanging off of window and we have items in our UI that are more than 13 levels deep into the require() stack.

Here is a JSFiddle that demonstrates the issue: http://jsfiddle.net/4Ms8p/3/. If you run this fiddle in its current state in IE 8 then you'll see an alert with "Foo is bar and bar is [Object object]". However, if you uncomment line 152 ("mybar = require('bar13');"), then it will additionally show an alert saying "Stack overflow at line 0".

Seems that IE only has an issue on functions that are directly attached to 'window', so my approach to solving this for now was to make an object on window called 'globals', and attach the require() function there.