Package: django-compressor-requirejs
Precompiler fordjango-compressorto integrateRequireJS-modules intobundles.This library does not use ther.jscompressor, but instead collects the
dependencies from your templates and resolves them into bundles, letting django-compressor do the compressing.InstallationFirst,install django-compressorinto your Django project and configure it. Then install django-compressor-requirejs:pip install django-compressor-requirejsand addrequirejs.RequireJSCompilerto yourCOMPRESS_PRECOMPILERSsetting:COMPRESS_PRECOMPILERS = (
    ('text/requirejs', 'requirejs.RequireJSCompiler'),
)You can now use the content type text/requirejs on your main RequireJS script tag:{% compress js %}
    <script type="text/requirejs" src="{% static "website/js/libs/require.min.js" %}"></script>
{% endcompress %}The library will by default generate a single bundle with all modules found in templates
and their dependencies. Dynamic dependencies will not be found. It also sets thebaseUrlto yourSTATIC_URL.IfCOMPRESS_ENABLEDisFalse, only the config will be added and RequireJS will load
modules one by one, without bundles.SettingsYou can control RequireJS with three options:REQUIREJS_PATHSis a dict in the same style as the RequireJS path config. This can be used for example
to make jQuery available in the main namespace ("jquery": "<somepath>/jquery.min").REQUIREJS_BUNDLESis a dict to specify which modules get bundled together:REQUIREJS_BUNDLES = {
   'abovethefold': ['website/awesome', 'website/evenmoreawesome'],
}Every module not mentioned in this setting will end up in themaincatch-all bundle.REQUIREJS_APP_ALIAS(defaultNone) allows the Javascript directory inside your static root to be addressed by
just the app name. Require/define calls towebsite/some_modulewill be searched as{{ STATIC_URL}}/website/<alias>/some_module.jsif not found in{{ STATIC_URL}}/website/.Under the hooddjango-compressor-requirejs makes use of RequireJS’sbundlesconfiguration option, making it possible to bundle
modules together and let RequireJS fetch the bundle when it needs one of the modules. The philosophy is that modules
bundled together are really often used together, which lowers the amount of requests the browser has to do.It uses the filter mechanism in django-compressor on the script tag used to load RequireJS itself, injecting a
configuration pointing RequireJS toSTATIC_URLand – if compression is enabled – the compressed bundle(s).Discovery of modules is done by searching all template directories for calls to RequireJS and parsing their
dependencies. This is a plain text search, no real parsing of Javascript or HTML is done (similar tomakemessages).
All found modules are then similarly scanned for their dependencies.Since no parsing or evaluation is done, any dynamic loading of dependencies with variables is not supported. If you
want to let django-compressor-requirejs pick it up, annotate the require() call with all options (if feasible, of
course).So django-require and compressor_requirejs exist.Yes, they do; and if you want to use the (otherwise excellent) r.js compressor with django-compressor, please take a
look atcompressor_requirejs. And if you do not use
django-compressor, visit etianen’sdjango-require.