I have an AMD project, which basically has the following structure :
samples/sample1/main
________________
* sharedpackage1/subfolder1/module1
* sharedpackage1/subfolder2/module1
* ./localmodule1
* ./localmodule2
* ./subfolder1/localmodule1
samples/sample2/main
________________
* sharedpackage1/subfolder2/module2
* sharedpackage2/subfolder1/subfolder1/module1
* ./localmodule1
* ./localmodule2
* ./localmodule3
* ./subfolder1/localmodule1
* ./subfolder1/localmodule2
* ./subfolder2/localmodule1
samples/sample3/main
________________
* sharedpackage2/subfolder2/subfolder1/module1
* sharedpackage2/subfolder3/module1
* ./localmodule1
* ./localmodule2
* ./localmodule3
* ./localmodule4
* ./localmodule5
...
I would like to use r.js to pack my project and end up with...
- a single
shared.jsfile for all samples that contains all modules insharedpackage1andsharedpackage2- and their dependencies - that are used in at least one of the samples - one
main.jsfile per sample that contains all the modules that are specific to that sample (the "local" modules)
Note that...
sharedpackage1andsharedpackage2are libraries that could contain hundreds of different interdependent modules- neither
sharedpackage1norsharedpackage2has a "root" (or "main") module that has all other modules within the package as dependencies - modules in
sharedpackage1can have modules fromsharedpackage2as dependencies - modules in
sharedpackage2only has other modules insharedpackage2as dependencies - modules from
sharedpackage1orsharedpackage2that are not used in any of the samples should not be included inshared.js - the sample-specific configuration should be as minimal and as generic as possible, so it can easily be generated at build-time with a Node script
Now, as long as every new sample has a main.js file as "root" module, it shouldn't be too hard to have every new sample automatically picked up by my build script without any additional configuration. So I'll manage with that.
What I can't seem to figure out from any of the documentation I've found, is how to create a single shared.js file that contains only those modules from sharedpackage1 and sharedpackage2 that are used in the samples without defining a shared module where I manually list all the individual dependencies for each main.js of each sample (which is ill-suited for my use case).
Is it possible to do this with r.js? If yes, how can I achieve this?
I received the following answer from jrburke on Github :