Short answer:
You need to create your own build procedure.
Long answer
The jQuery build procedure only works because jQuery defines its modules according to a template that allows the convert function to convert the source into a distributed file that does not use define . If someone wants to replicate what jQuery does, there is no shortcut: 1) the modules must be designed according to a template that will disable define calls, and 2) you must have a custom conversion function. This is what jQuery does. All the logic that combines jQuery modules into one file is in build / tasks / build.js .
This file defines the custom configuration that it passes to r.js An important option is:
out , which is set to "dist/jquery.js" . This is the only file created by optimization.
wrap.startFile , which is set to "src/intro.js" . This file will be added to dist/jquery.js .
wrap.endFile , which is set to "src/outro.js" . This file will be added to dist/jquery.js .
onBuildWrite , which is set to convert . This is a custom feature .
The conversion function is called every time r.js wants to output the module to the final output file. The result of this function is that r.js writes to the destination file. It performs the following actions:
If the module is from the var/ directory, the module will be converted as follows. Let us consider the case of src / var / toString.js :
define([ "./class2type" ], function( class2type ) { return class2type.toString; });
It will become the following:
var toString = class2type.toString;
Otherwise, the call to define(...) is replaced by the contents of the callback passed to define , the final return is lost and any exports assignments are deleted.
I missed the details that are not specifically relevant to your question.
Louis
source share