Requirejs - 带变量的动态模块依赖注入

Requirejs - Dynamic module dependency injection with variables

我们在 angular 应用程序中使用 requirejs 创建了动态模块注入。现在我们已经为每个模块(commonModule、usersModule)分别创建了函数的参数实例。我们如何才能在 requirejs 和 angularjs 中使模块依赖注入动态化?

var _moduleFiles = ["common/module", "user/module"];

require(_moduleFiles, function(commonModule, usersModule) {
   var app = angular.module('Myapp', [commonModule, usersModule]);
});

我调查过这个问题,发现可能无法在requirejs中实现动态模块注入。

Dynamic code loading (done in AMD systems via require([], function (){})) is a basic requirement. CJS talked about it, had some proposals, but it was not fully embraced. Node does not have any support for this need, instead relying on the synchronous behavior of require(''), which is not portable to the web.