A bridge from Webpack to Django
Project description
Django Webpack Bridge
Creates a bridge from webpack to django.
Supported Versions
Django >= 2.1 Webpack >= 4.44.2
How to Use
-
Add the packages to
setup.py
andpackage.json
.- Unimplemented: Add
django-webpack-bridge
to install from public registries. - To install from git
- python:
'django-webpack-bridge @ https://github.com/uw-it-aca/django-webpack-bridge/tarball/master'
- nodejs:
"django-webpack-bridge": "https://github.com/uw-it-aca/django-webpack-bridge.git"
- python:
- Unimplemented: Add
-
Add the plugin to
webpack.config.js
const DjangoBridgePlugin = require('django-webpack-bridge'); module.exports = { ..., plugins: [ ..., new DjangoBridgePlugin(), ], }
django-webpack-bridge
will use the variables frommodule.exports.output
-
Add the following to
settings.py
INSTALLED_APPS += [ 'webpack_bridge', ] STATICFILES_DIRS = [ '{same as module.exports.output.path from webpack.config.js}', ]
-
In the
template.html
{% load webpack_bridge %} {% render_webpack_entry 'entry point name' js='defer' %}
Settings
BRIDGE_SETTINGS = {
# Name of the manifest file
'manifest_file': 'manifest.json',
# Boolean to turn caching on and off
'cache': not settings.DEBUG,
# Timeout duration for the cache
'cache_timeout': 86400, # 1 Day
# Namespace for the cache
'cache_prefix': 'webpack_manifest',
# Maps a tag group to a group of tags
'group_to_extensions': {
'script': ('js', ),
'style': ('css', ),
},
# Maps a tag group to a html tag
'group_to_html_tag': {
'script': '<script src="{path}" {attributes}></script>',
'style':
'<link rel="stylesheet" type="text/css"'
+ ' href="{path}" {attributes}>',
},
# Time between updaing the manifest from the file while compiling
'compiling_poll_duration': 0.5,
}
group_to_extensions
and group_to_html_tag
combine to create a multi-key map from a group of file extensions to a html tag. Eg. (js, jsx) -> <script src="{path}" {attributes}></script>
path
: Will be replaced with the bundle path
attributes
: Will be replaced with any attributes specfied when when calling 'render_webpack_entry'. Attributes are grouped by file extension
The following settings can be passed to DjangoBridgePlugin
{
path: 'defaults to module.exports.output.path',
publicPath: 'defaults to module.exports.output.publicPath',
fileName: 'defaults to manifest.json',
}
Development
Running tests
- Create and activate a python virtual env of your choice (optional).
- Run
pip install .
- Run
DJANGO_SETTINGS_MODULE=test_files.settings python -m django test webpack_bridge
Running the Demo
- Run
docker-compose up --build
- Open
localhost:8000
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-webpack-bridge-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a626d9bbcc65840f48f1b4b7e0577b8d96975e49f63b39bac61c0ac4eaf51f14 |
|
MD5 | ccd9b009434f4a60ae1e1f05b4ba72fe |
|
BLAKE2b-256 | 1f1dbc761e6e90a583b48bd368d460a8285e8552c7fb7e13e34c5852df5de6b4 |
Hashes for django_webpack_bridge-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ece8128f9c9d63897beaaca6f6fe16ced9511e36a3baf23794bdf3dd11395e09 |
|
MD5 | 5b032aa0bf388159bcdc4c278e05ce57 |
|
BLAKE2b-256 | 22f6fffd188cbb513eaccfc7d402b85361167b1604783ac49a9e2430b8992275 |