#javascript #lodash @tidev shim for a browserify UMD library

Oscar Brito

Browserify turned out to be a very good tool I must admit. While working on my divhide-core library, some days from before releasing version 1.0.0, one of my last tickets was for to make it run on titanium.

Titanium uses javascript so it should be easy enough to use divhide-core, I thought. For now, divhide-core just depends on lodash and that is the focus of this blog post.

Lets rewind a bit now. I'm using browserify to create a single bundle, without external libraries and configuration steps. Therefore, my build task is taking everything I need and creating the divhide.js file, which will be used on the Browser, on titanium and other javascript platforms.

Let's cut to the chase now. To integrate lodash 2.4.1 on a browserify UMD bundle we need the following shim:

"use strict";

/// lodash titanium shim. If window is undefined set global variable
var global = undefined, isBrowser = false;  
try{ isBrowser = (window !== undefined); }catch(e){}  
if(!isBrowser){ global = this; global.global = global; }

The reason for this is because when titanium runs it has no reference to the window object. Lodash's runInContext function needs that to initialise itself.

Please feel free to check divhide-core and give some feedback.

Oscar out.