I am building a library which is a set of folders containing Model View Controller Javascript files.
Each files has dependencies declared using require syntax:
define([
'modules/moduleA/src/moduleAModel',
'modules/moduleA/src/moduleAController',
], function(moduleAModel, moduleAController) {
function moduleAView(param) {
// ....
}
I am compiling this library using GruntJS with the great "grunt-contrib-requirejs".
The problem is that as a library there is no entry point, no main.
I want users to be able to use it by calling each module when they need it.
Here are my questions:
Firstly:
How can I build one javascript file for the library which includes all the modules without declaring them one by one ?
Secondly:
How can I reuse this library later on another project ?
I tried this :
define(function(require) {
var myLibrary = require('js/external-libs/myMinifiedLibrary.min');
var moduleAV = new moduleAView();
But of course second lines fail, is there something like require(myLibrary.moduleAView)
?
What would you suggest ?
Update:
I found out that when you have minified on one single file all your modules, you have multiple defines on one page, this is interpreted as a script for requirejs and you have to load it twice ! (first time the whole file, second times your main).
Then my 'main' or entry point is built manually (which is still a problem) on rockerest answers.
So solution to my second question is on this post:
http://jaketrent.com/post/dynamically-require-optimized-modules-requirejs/