django-webpack-loader is used to support referencing Webpack bundles in Django's templates.
- A Django template uses
django-webpack-loader
's directives to reference a Webpack bundle. django-webpack-loader
looks at the Django settings to getBUNDLE_DIR_NAME
andSTATS_FILE
.- It then creates URLs that map to Webpack's bundles and substitutes the template directives with these URLs by render time.
Taken from the official repo:
DEFAULT_CONFIG = {
'DEFAULT': {
'CACHE': not DEBUG,
'BUNDLE_DIR_NAME': 'webpack_bundles/',
'STATS_FILE': 'webpack-stats.json',
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
'IGNORE': [r'.+\.hot-update.js', r'.+\.map']
}
}
If your configuration does not contain one of the above keys, then the default value will be used.
# project/settings/base.py
INSTALLED_APPS = [
...,
'webpack_loader',
...
]
# project/settings/dev.py
# django-webpack-loader will use this as a base directory for the `BUNDLE_DIR_NAME` configuration.
STATICFILES_DIRS = (
abs_path('bundles/build-dev'),
)
WEBPACK_LOADER = {
'DEFAULT': {
# Webpack outputs bundles in bundles/build-dev/ when in development mode.
'BUNDLE_DIR_NAME': '/',
'STATS_FILE': abs_path('bundles', 'webpack-stats.dev.json'),
}
}
# project/settings/prod.py
STATICFILES_DIRS = (
abs_path('bundles/dist'),
)
WEBPACK_LOADER = {
'DEFAULT': {
# Webpack outputs bundles in bundles/dist/ when in production mode.
'BUNDLE_DIR_NAME': '/',
'STATS_FILE': abs_path('bundles', 'webpack-stats.prod.json')
}
}