我知道你说过你自己解决了这个问题,但是,这是我的看法。
您的解决方案包括使用自定义加载程序,但是,也许您可以用不同的方式解决它。
第一步,在你的webpack.config
在配置对象中添加这些:
context: __dirname, //set the context of your app to be the project directory
node: {
__dirname: true //Allow use of __dirname in modules, based on context
},
然后,将其添加到您的插件列表中:
new webpack.DefinePlugin({
SEPARATOR: JSON.stringify(path.sep)
})
这将取代所有SEPARATOR
对于您正在使用的系统,模块中的实例具有正确的路径分隔符(您必须require('path')
在你的webpack.config
为了这个工作)
最后,在您想要的任何模块中,您现在可以通过执行以下操作来获取其名称
var moduleName = __dirname.replace(new RegExp(SEPARATOR, 'g'), '.');
所以,例如
//in the file app.module.js
var moduleName = __dirname.replace(new RegExp(SEPARATOR, 'g'), '.');
module.exports = framework.module(moduleName, [
require('./api/api.module').name
])
//in the file app/api/api.module.js
var moduleName = __dirname.replace(new RegExp(SEPARATOR, 'g'), '.');
module.exports = framework.module(moduleName, [
])