css-ratiocinator icon indicating copy to clipboard operation
css-ratiocinator copied to clipboard

Simplify JS dependency inclusion

Open begriffs opened this issue 12 years ago • 2 comments

Code inside of lib/ needs to be included in both Phantom and a its simulated browser page. Phantom supports require() but the simulated page does not. This leads to weird code like this

var MODULE_NAME = (function () {
  var my = {};

  my.foo = function () { ... };
  // etc...

  if (typeof exports !== 'undefined') {
    _.extend(exports, my);
  }
  return my;
}()); 

This way it uses exports if that exists, otherwise it declares a global variable for the module which a page can reference.

Simplify this!

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

begriffs avatar Mar 23 '13 18:03 begriffs

@joshuarh do you have any ideas?

begriffs avatar Mar 23 '13 18:03 begriffs

You could move that helper somewhere, so it's not repeated, maybe something like browserify would help. I'm not sure I'd have to play with it a bit

losingkeys avatar Mar 24 '13 02:03 losingkeys