Here's the deal. If everything loaded through text!
has been optimized with r.js
, then all text has been included in the output of r.js
, and you can stub the plugin.
However, if you want to have the ability to use text!
to load text that has not been through the optimization process, then you must have the text!
plugin available at run time. In this case you cannot stub it, otherwise RequireJS won't be able to load the text pieces that you have not optimized because there won't be a text!
plugin for RequireJS to use.
In an application that contains modules loaded by text!
that have been optimized and modules loaded by text!
that have not been optimized, the following will happen:
For a module that has been optimized, RequireJS will find a
define
call with module's name (because this is part of whatr.js
does). For instance,define("text!foo", [...], function(...)
. In a case like this, RequireJS will not try to use thetext!
plugin to load this module. It will just load the module directly. (This has to be true otherwise stubbing thetext!
plugin would cause RequireJS to fail as soon as any optimized module that usestext!
is required.)For a module that has not been optimized, RequireJS will ask
text!
to load the module.
Unless special measures are taken, r.js
automatically includes the entire text!
plugin when it finds it among the dependencies of a bundle of modules.
So to exclude the text module specifically, use the excludeShallow
option. Your new command line/bat file would look something like this:
node r.js -o name=Main excludeShallow=text out=main-master-built-text-path.js