我想在我的应用程序中使用自定义require()
函数。 即我有节点的标准require()
和一个自定义我写了需要从根开始的文件名为rootRequire()
在内部它是所有:browserify检测自定义要求()
// rootRequire.js
var path = require('path');
var rootPath = __dirname;
global.rootRequire = function (modulePath) {
var filepath = path.join(rootPath, modulePath);
return require(filepath);
};
module.exports = rootRequire;
但是,即使rootRequire()
内部使用节点require()
,它不拿起通过该方法所需的任何文件
例子:
require('rootRequire.js');
rootRequire('/A.js'); // server side it works, in the browser I get an error saying can't find module A.js
你有没有想出这个解决方案? – user1157885
nope。开始使用webpack,它支持并绕过这个问题 – Stefan