Package: compressor_requirejs
v1.5license changed to the MITv1.4support for python 3.4support for django 1.9.xsupport for django-compressor up to 1.6 (2.0 not officially supported but may work in some circumstances)support for utf8 encoding in files (required encoding)v1.3install_requires added,support for django compressor 1.4 precompiler constructorv1.2invalidate cache on compiling error,support for custom loggingIntroductionThis module ables django compressor to compile requirejs files into one
or a few bigger files using r.js.Features:compiling plenty of files into one filemaking a few compiled files for splitting functionalityall features of django compressor i.e.:caching files,adding hashes,processing with django template markup,post compilingtracing build files for modification (caching results)RequirementsDjango >= 1.6django_compressor >= 1.3 and < 2.0PyExecJs >= 1.1.0node jsInstallationAddcompressor_requirejsto installed appsSetupdjango_compressorproperties for working with django
compressorSetupcompressor_requirejs:SetCOMPRESS_PRECOMPILERSof django compressor for using with
standard markup in compress tagsSetCACHEbackends for django compressor and requirejs plugin,
recomended for development is'default'withDummyCacheand'locmem'withLocMemCacheSetCOMPRESSOR_REQUIREJS_TMPto a customexistingtemporary directory pathCACHES={'default':{'BACKEND':'django.core.cache.backends.dummy.DummyCache'},'locmem':{'BACKEND':'django.core.cache.backends.locmem.LocMemCache'}}COMPRESS_PRECOMPILERS=(('text/requirejs','compressor_requirejs.compressor.r_precompiler.RequireJSPrecompiler'),)COMPRESSOR_REQUIREJS_TMP=django_project_path_join('tmp')Advanced configuration#COMPRESSOR_REQUIREJS config#absolute path to r.js#default: path in resources of this packageCOMPRESSOR_REQUIREJS_R_JS='path/to/r.js'#absolute path to temporary directoryCOMPRESSOR_REQUIREJS_TMP='/tmp'#path to global configuration for requirejs bulid aka 'mainConfigFile' in r.js configuration# WARNING setting this path overwrites built in global config of this plugin and some feature can not workingCOMPRESSOR_REQUIREJS_GLOBAL_CONFIG='path/to/global/requirejs/config.js'#setup compressor_requirejs caching backend, preferred local memory backend mainly for development,#backend should be configured in django CACHE configuration#default: 'locmem'COMPRESSOR_REQUIREJS_CACHE_BACKEND='locmem'#timeout for caching results in cache (in seconds)#default: 3600COMPRESSOR_REQUIREJS_CACHE_TIMEOUT=3600#node js executable path, it is preferred to have mapped 'node' in your PATH#default: nodeCOMPRESSOR_REQUIREJS_NODE_EXECUTABLE='node'#setup custom logging function for outputdeflogging_compressor_requirejs(text):importlogginglogger=logging.getLogger('mainapp.custom')logger.debug(text)COMPRESSOR_REQUIREJS_LOGGING_OUTPUT_FUNCTION=logging_compressor_requirejsUsingPrepare at least two js files, one build file and one module file:build.js({baseUrl:'.',name:'main'})main.jsrequire([],function(){console.log('wow, its working');});Put those files in static directory of your app.build.jspointing
tomain.jswithnameattribute, so launching build file compilemain.jswith other dependencies.Django template configuration{% compress js %}
     <script type="text/requirejs" src="{{ STATIC_URL }}mainapp/js/build.js"></script>
{% endcompress %}Of course you have to includerequire.jsfile, ex:{% compress js %}
    <script src="{{ STATIC_URL }}mainapp/js/require.js"></script>
{% endcompress %}Advanced featuresYou can use django template language tags in your js files. It can be
processed with django compressor’s template processors but there is a
hack to omit this markup during requirejs compilation.//>startExclusionvarimportantVariableExcludedDuringCompilationButVisibleInRenderedFile={{PROJECT_VARIABLE}};//>endExclusionThose tags are used to exclude fragment of code (commenting it) during
requirejs compilation, and after compilation it will be available, and
can be processed by django compressor.Also you can use tags in string without above markup:varx='{{ STATIC_URL }}/path/';Global js library mappingsYou can use global path mappings for javascript files,
for example if you have a few apps in project and one handle main libraries simply add them to global paths.COMPRESSOR_REQUIREJS_REQUIRED_LIBS={}In django object simply type key value elements, where key is valid path mapping and value is path to js file.IMPORTANTmapping name can be only solid string without dots eg.:mapping_for_pathnotmapping.for.pathpath can be relative to current project and will be processed with defined static file finderCOMPRESSOR_REQUIREJS_REQUIRED_LIBS={'jquery':'mainapp/js/libs/jquery-2.1.0.min.js'}