Skip to main content

Transpile JavaScript without running an extra node.js process.

Project description

django-compressor-js

Instead of running an extra node.js process watching for changes in your Javascript, this precompiler for django-compressor will convert any ES6 code into ES5 automagically.

Install

  1. pip install django-compressor-js
  2. Add precompiler (text/es6 can be anything, but it has to match the script type in the template)
COMPRESS_PRECOMPILERS = (
    ("text/es6", "django_compressor_js.precompilers.BabelCompiler"),
)
  1. Add to HTML template
{% compress js %}
	<script src="{% static 'js/test-es6-code.js' %}" type="text/es6"></script>
{% endcompress %}

Caveats

Most ES6 syntax seems to work pretty well, but requiring modules doesn't import correctly. Also, this approach adds some latency when compressing on the fly (i.e. COMPRESS_OFFLINE = False).

Run tests

poetry run pytest

Credits

dukpy and django-compressor for doing all the hard things.

Project details


Release history Release notifications

This version

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-compressor-js, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size django_compressor_js-0.1.0-py3-none-any.whl (2.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-compressor-js-0.1.0.tar.gz (2.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page