It might indeed not make sense for your application to optimize all modules into one single file. r.js
supports this kind of scenario. What you have to do is use the modules
option and define as many output files as you need. A generic illustration of this could be:
modules: [
{
name: 'main',
exclude: [ "viewA", "viewB" ],
},
{
name: 'viewA',
exclude: ['core']
},
{
name: 'viewB',
exclude: ['core']
}
]
The setup above assumes that the source to be optimized has modules named main
, viewA
and viewB
. It would create 3 optimized bundles: a core
that contains all core modules that would be loaded in any case, viewA
which represents a group of modules to be loaded in circumstances so and so, and viewB
which represents a group of modules to be loaded in other circumstances.
How you should setup your modules
parameter depends on the specifics of your application.