How to use NodeJS global module objects in RequireJS modules

[亡魂溺海] 提交于 2019-12-23 08:52:18

问题


I decided to use RequireJS as my module loader in NodeJS.

Unfortunately, the modules I define don't have access to some of the "global" objects that would be be available if the modules were loaded using the CommonJS method. This includes the objects that are located in the module scope, such as __dirname and __filename.

Is there a relatively simple approach to using these objects in the RequireJS modules?


回答1:


This is covered on the requirejs issues site on github (https://github.com/jrburke/requirejs/issues/89) and the workaround they seem to suggest is to use module.uri instead.



来源:https://stackoverflow.com/questions/9027429/how-to-use-nodejs-global-module-objects-in-requirejs-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!