tl;dr: How do I keep the text.js plugin out of my optimized file when all my text dependencies are inlined?
I\'m using the Require.js optimizer (via
The text plugin is really required since RequireJS needs to check if the plugin implements the method normalize
before retrieving the proper module ID.
The way to remove the text plugin from the build is to use the onBuildWrite
setting to create an empty plugin module as described on this issue comment: https://github.com/jrburke/r.js/issues/116#issuecomment-4185237 - This feature should land on a future version of r.js
Edit:
r.js now have a setting called stubModules
that does exactly that:
//Specify modules to stub out in the optimized file. The optimizer will
//use the source version of these modules for dependency tracing and for
//plugin use, but when writing the text into an optimized layer, these
//modules will get the following text instead:
//If the module is used as a plugin:
// define({load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
//If just a plain module:
// define({});
//This is useful particularly for plugins that inline all their resources
//and use the default module resolution behavior (do *not* implement the
//normalize() method). In those cases, an AMD loader just needs to know
//that the module has a definition. These small stubs can be used instead of
//including the full source for a plugin.
stubModules : ['text']
For more r.js options check the example.build.js file.