dependencies - Browser or server version of module -
using requirejs , javascript modules, i'd share code between server , browser, there 4 situations.
1/ module server
define([], function() { if(typeof window != 'undefined') return null; // server //module code })
2/ module browser
define([], function() { if(typeof window == 'undefined') return null; // browser //module code })
3/ module shared
define([], function() { //module code })
4/ module different code server/browser
define(['require'], function(require) { if(typeof window == 'undefined') // server version { return require('nodejs module'); } // browser version })
what want solve better way including module code browser, have past whole code of browser version. nodejs require sync, works. in browser have use like
define(['require'], function(require) { if(typeof window == 'undefined') // server version { return require('nodejs_module'); } require(['module_for_browser'], function(module_for_browser) { return module_for_browser; }) }
but can't return it!
most libraries have same code both , manage internally checking window, not. want use same eventemitter api server require('events').eventemitter , browser compatible version https://github.com/hij1nx/eventemitter2
Comments
Post a Comment