我真的厌倦了require()中相对路径的义务。 您对此解决方案有何看法?我不确定安全隐患。
GLOBAL.$require = function(mod){
return require(path.join(__dirname, mod));
};
它将node_modules
作为默认require()
的基本路径,但我添加了一个$require()
,其中包含从项目根开始的路径。
我没有尝试过编辑NODE_PATH的解决方案 https://lostechies.com/derickbailey/2014/02/20/how-i-work-around-the-require-problem-in-nodejs/ 并没有强迫你改变所有npm依赖的路径?