JavaScript libaries such as RequireJS and the like can be used to declare one or more dependencies of a certain JavaScript file.
For example, the actual code of a JavaScript file a.js may be wrapped like so:
a.js
require(["b"], function(b) {
// actual code using logic declared in b.js
});
We can then use logic declared within b.js, a separate file.
Question:
Is it possible to define this dependency in a third file, c.js, maybe an application-wide config file defining all dependencies of the application, but allowing a.js to use logic of b.js the same way as it would be defined in the way as shown above?
It’s probably not possible with RequireJS, but is there a different library which supports this use case (assuming it’s technically possible given the nature of the language)?
I wouldn’t use RequireJS for this, but nCore.
It does exactly what you want, using a
dependency.jsonfile. Also, it “compiles” your js files into one for production.You can see an example of application here (look at the
modules/folder).