Django integration for Rspack, a Rust-powered bundler compatible with webpack.
django-rspack is the Django equivalent of Shakapacker for Rails. It reuses the same JavaScript/npm package from Shakapacker for the actual Rspack dev server, config, manifest handling, and build pipeline. The Python side is a thin Django app that integrates Rspack into your Django project.
- Manifest-based asset resolution — Reads the Rspack manifest.json to resolve pack names to fingerprinted paths
- Django template tags —
{% rspack_bundle_js %},{% rspack_bundle_css %}to inject script/link tags - Management commands —
rspack_install,rspack_dev_server,rspack_compile - Dev server proxy middleware — Proxies asset requests to the Rspack dev server in development
- Django staticfiles integration — Works with
collectstaticfor production asset serving - Content hashing — Fingerprinted filenames for production cache busting
- Code splitting support — Handles webpack/rspack entrypoints with multiple chunks
- Python 3.10+
- Django 4.2+
- Node.js 18+ (for Rspack)
pip install django-rspack# settings.py
INSTALLED_APPS = [
...
"django_rspack",
]python manage.py rspack_installThis creates:
config/shakapacker.yml— Configuration filerspack.config.js— Rspack configurationapp/javascript/packs/application.js— Default entry pointpackage.json— Node.js package file (if it doesn't exist)
npm install{% load rspack %}
<!DOCTYPE html>
<html>
<head>
{% rspack_bundle_css "application" %}
</head>
<body>
{% rspack_bundle_js "application" %}
</body>
</html>python manage.py rspack_dev_serverConfiguration is loaded from three sources (in order of precedence):
- Django settings (
RSPACKdict in settings.py) - YAML config file (
config/shakapacker.yml) - Bundled defaults
# settings.py
RSPACK = {
"source_path": "app/javascript",
"source_entry_path": "packs",
"public_root_path": "public",
"public_output_path": "packs",
"dev_server": {
"host": "localhost",
"port": 3035,
},
}| Variable | Description |
|---|---|
RSPACK_ENV |
Override environment detection (development, production, test) |
RSPACK_DEV_SERVER_HOST |
Override dev server host |
RSPACK_DEV_SERVER_PORT |
Override dev server port |
RSPACK_ASSET_HOST |
CDN or asset host URL |
See Configuration Guide for all options.
{% load rspack %}
{# JavaScript bundle with defer (default) #}
{% rspack_bundle_js "application" %}
{# CSS bundle #}
{% rspack_bundle_css "application" %}
{# Generic bundle (specify type) #}
{% rspack_bundle "application" "js" %}
{# Get just the asset path #}
{% rspack_asset_path "application.js" %}
{# Get the full URL (with asset host) #}
{% rspack_asset_url "application.js" %}# Install configuration and scaffolding
python manage.py rspack_install
# Start the development server
python manage.py rspack_dev_server
# Compile assets for production
python manage.py rspack_compileAdd the middleware to proxy asset requests to the Rspack dev server during development:
# settings.py
MIDDLEWARE = [
"django_rspack.middleware.RspackDevServerMiddleware",
...
]The middleware only activates in development mode when the dev server is running.
-
Compile assets:
python manage.py rspack_compile
-
Collect static files:
python manage.py collectstatic
-
Configure your web server to serve the
public/packs/directory.
See Deployment Guide for detailed instructions.
# Clone the repository
git clone https://github.com/shakacode/django-rspack.git
cd django-rspack
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Lint
ruff check src/ tests/- Shakapacker — The Rails equivalent (Ruby gem + npm package)
- Rspack — The Rust-powered bundler
- React on Rails — React integration for Rails
MIT License. See LICENSE for details.
Created and maintained by ShakaCode.