It's not clear to me how to bundle many js files into one file. When I run the optimizer the result is an output directory with a structure mirroring my source directory. All files in it are minified. That's good. But what I was looking for was one minified file. I don't see that. So my project is optimized but not concatenated.
I must be misunderstanding something about how to configure the process. Here's what I'm doing:
I have r.js and build.js in a directory. In a folder off that directory I have sourcejs. That sourcejs folder has application.js (the module I want the optimizer to trace). That module "requires" lots of stuff in nested folders below it.
Here's the build file:
({
appDir: "sourcejs",
baseUrl: ".",
dir: "sourcejs-build",
mainConfigFile: 'sourcejs/application.js',
modules: [
{
name: "application"
}
]
})
I'm assuming pointing the optimizer to the main module, application.js, will be all that's necessary to produce the desired output from there. It will trace dependencies therein and find its way to all sub-folders and files. The optimizer does appear to find all source. I get output:
Tracing dependencies for: application
Uglify file: C:/o/sourcejs-build/application.js
Uglify file: C:/o/sourcejs-build/controller.js
Uglify file: C:/o/sourcejs-build/modules/controllers/auxcontroller.js
Uglify file: C:/o/sourcejs-build/modules/controllers/documentcontroller.js
...long list of files
application.js
----------------
application.js
The output file application.js is not a concatenated version of the project but rather just a minified version of itself.
What is my misunderstanding here?
By default all the js files get minified in the optimized directory. As far I understand according to the configuration you supplied it would bundle application.js and the modules it depends into the same file.
Aplication.js and it's dependencies goes into the Application.js.
Optimiziation process bundles only files that are mentioned in the modules and leaves other files as minified. If you want files to be bundles you have to provide the bundled file names (most probably you would be generating new files. ) You have to say create: true
in the modules to create new files during build process.
{
name : bundle1,
create : true,
include: ['dep1', 'dep2']
},
{
name : bundle12,
create : true,
include: ['depA', 'depB']
}
Like this you have to specify the bundle configuration so that they are created during the build process.