We are creating a framework that we intend to use across multiple projects. All projects will use require.js to manage modules and dependencies.
Ideally I'd like to use the r.js optimizer to compile the framework into a single file that can be provided to the applications that use it. That file will contain all modules of the framework such that in my application I can write code like:
define(["framework/util/a", "framework/views/b"], function(A, B) {
var a = new A();
// etc...
});
But it appears there are two problems with this approach.
- Depending on
framework/util/adoesn't tell require.js that it needs to loadframework.jsin which it will findutil/a - The optimize tool generates names for all modules included in
framework.jssuch asdefine("util/a", function() { ... } );Even if require.js loadedframework.jsthere is nothing that tells it that the defined moduleutil/ais a relative module toframeworkand as such is identified asframework/util/a
Am I missing something or is a better approach to structure my framework as a CommonJS package and use require.js's packages configuration option?