public
Created

Require that works everywhere, tested on all browsers IE6 or more modern and Node! Weighs 2KB. Save this file as "imports.js", then include it as a script tag for the browser, and use as below for your own code - Node works automatically. `;module.exports=require('./path/to/imports')('hello',function(mods){ /* your code here */ return 'Hello World!' },['./needed','./dependency']);` This gist is powered by https://github.com/amark/theory, go there to find out more. Enjoy!

  • Download Gist
imports
1 2 3 4 5 6 7 8 9 10
(function(){var m=m||{},g=m,a={id:"imports"};g.opts=g.opts||{};g.d={l:{},n:{},a:{},w:{}};g.z="undefined"!==typeof GLOBAL&&GLOBAL.global&&GLOBAL.process&&GLOBAL.process.env&&GLOBAL.process.pid&&GLOBAL.process.execPath?function(){global.node=g.node=!0;module.exports=function(b,e,d){var c=a.r(b,e,d);c.s=g.y||(module.parent||{}).filename;a.e(a.d(c.d,c.s,{}),function(b,e){c.a[b]=a.n(e=require(g.y=e))?void 0:e});return c.i(c.a)}}:function(){var b=window;g.page=!0;b.root=g;b.console=b.console||{log:function(a){return a}};
location.local="file:"===location.protocol?"http:":"";b.__dirname="";b.module={exports:b.exports={}};a.l=function(a,b){var c="script",f=document.createElement(c);module.sync=null!==f.onload&&f.readyState?1:0;var h=2166136261,g=a.length,k=b,q=/=\?/,r=window.setTimeout,n,m,p=function(a){document.body&&(a=a||n)&&f&&document.body[a]?document.body[m=a](f):r(p,0)};if(q.test(a)){for(;g--;)h=16777619*h^a.charCodeAt(g);window[c+=0>h?-h:h]=function(){k.apply(k,arguments);delete window[c]};a=a.replace(q,"="+
c);b=0}f.onload=f.onreadystatechange=function(){if(m&&/de|m/.test(f.readyState||"m")){b&&b();p(n="removeChild");try{for(b in f)delete f[b]}catch(a){}}};f.src=a;b&&p(n="appendChild")};a.l("#");b.require=module.require=function(b){if(!b)return require;if(a.q(b)==a.q(a.id))return a.r;var d,c=0;a.e(b=a.L(b)?b:[b],function(f){a.g(f,function(a){++c&&b.length<=c&&d&&d(a)})});return function(a){d=a}};require.resolve=a.f;require.cache={};a.y();b.imports=a};a.T=function(a){return"string"==typeof a?!0:!1};a.L=
function(a){return a instanceof Array?!0:!1};a.F=function(a){return a instanceof Function?!0:!1};a.O=function(b){return b instanceof Object&&!a.L(b)&&!a.F(b)?!0:!1};a.n=function(b){return a.O(b)?a.e(b,function(a,b){if(b)return!0})?!1:!0:!1};a.h=function(a,e){return Object.prototype.hasOwnProperty.call(a,e)};a.e=function(b,e){var d=0,c=0,f,g,l=a.F(e),k=function(a,b){void 0!==b?(g=g||{},g[a]=b):(g=g||[],g.push(a))};if(a.L(b))for(f=b.length;d<f;d++){if(c=d+a.e.i,c=e(b[d],c,k),void 0!==c)return c}else if(a.O(b))for(d in b)if(a.h(b,
d)&&(c=e(b[d],d,k),void 0!==c))return c;return l?g:a.e.i?0:-1};a.e.i=1;a.e.u=function(b,e){var d={};a.e(b,function(b,f){a.h(d,f)||(d[f]=b)});a.e(e,function(b,f){a.h(d,f)||(d[f]=b)});return d};a.o=function(b){a.o.l=a.o.l||[];if(!b)return a.e(a.o.l,function(a){a.fn&&a.fn()});var e={fn:b,off:function(){e.fn=!1}};a.o.l.push(e);return e};a.r=function(b,e,d){var c={n:b,i:e,d:d,a:{}};c.d=a.L(c.d)?a.e(c.d,function(a,b,c){c(a,1)}):c.d;if(g.node)return c;c.z=function(){return a.d(c.d,c.s),c.l()};c.l=function(){if(!c.g&&
!a.e(a.d(c.d,0,{}),function(b,e,d){if(!(d=g.d.l[e])||2===d)return!0;d&&(d.l&&b&&a.T(b)&&void 0===c.a[b])&&(c.a[b]=d.l)}))return c.o.off(),c.g={l:c.i(c.a)},module.exports=exports=c.g.l,c.s&&(g.d.l[c.s]=c.g,a.o()),c.g.l};c.o=a.o(c.l);c.m=function(a){module.on=c.m=!1;g.d.n[c.s=a]=c.n;if(g.d.a[a]=c.d)g.d.l[a]=2;return c.z()};module.on=require.ing?c.m:c.m(a.s(1))||!1};a.d=function(b,e,d,c){a.e(b,function(f,h,l,k){l=h;k={p:h};e&&(delete b[h],b[l=a.f(e,a.p(l))]=f);a.L(f)&&(delete b[h],f=b[l]=a.e(f,function(b,
c,d){d(a.f(e,a.p(b)),1)}));a.O(f)&&(k.d=f,d&&a.d(f,0,d));f&&a.T(f)&&(k.n=f);if(d)k.s=a.u(a.p(l)),(h=d[k.s])&&1!==h||(d[k.s]=(c?1:k.n)||a.q(l),1!==h&&k.s&&a.T(k.s)&&(f=g.d.a[k.s])&&(a.O(f)||a.L(f))&&a.d(f,0,d,1));else return a.g(l,k)});return d};a.u=function(a){if(!g.page)return a;var e=document.createElement("div");e.innerHTML='<a href="'+a+'">x</a>';return e.firstChild.href};a.p=function(a){return g.page?/\.js$/i.test(a)?a:a+".js":a};a.q=function(b){if(!a.T(b))return"";b=b.replace(/^\./,"");return b.split("/").reverse()[0].replace(/\.js$/i,
"")};a.f=function(a,e){if(!a||"."!=e.charAt(0))return e;var d=a.split("/");s=e.split("/");d.pop();for(a=0;a<s.length;a++)e=s[a],".."==e?d.pop():"."!=e&&d.push(e);return d.join("/")};a.g=function(b,e,d){if(a.q(b)==a.q(a.id))return a.r;e=e||{};var c=g.d.w;if(module.sync){if(!d&&!a.n(c)){c[b]=e;e.d&&(c=g.d.w=a.e.u(c,e.d));return}c[b]=e;e.d&&(c=g.d.w=a.e.u(c,e.d))}var f=a.p(b),h=a.u(f);d=function(d){!1!==d&&(console.log(f," loaded"),g.d.l[h]=1,module.on&&module.on(h),a.F(e)&&e(d));a.o();!module.sync&&
e.d&&a.d(e.d);module.sync&&(delete c[b],a.e(c,function(b,d,e){delete c[d];a.g(d,b,1);return 1})||(c=g.d.w=!1))};if(g.d.l[h]||0===g.d.l[h])return d(!1);g.d.l[h]=0;require.ing=!0;try{a.l(f,d)}catch(l){console.log(l)}console.log("loading",f)};a.s=function(){var b=document.getElementsByTagName("script"),b=(b[b.length-1]||{}).src;return a.q(b)===a.id?location:b||location};a.z=function(a,e){try{(window.execScript||function(a){window.eval.call(window,a)})(a)}catch(d){console.log(d,a)}};g.c=0;a.y=function(b){if(g.page){var e=
document.getElementsByTagName("script"),d,c;for(c in e){var f=e[c];b=f.src||b;f.id||!f.innerHTML||a.q(f.src)!==a.q(a.id)?!1:d=f}d&&(a.z(d.innerHTML,"config"),d.id=a.id+g.c++);return b}};g.i=(g.z(),a.y)})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.