From 1232f8969d836345b5319612ffa2590cd7fdc64d Mon Sep 17 00:00:00 2001 From: Devendra K Rane Date: Mon, 26 Mar 2018 18:51:42 +0530 Subject: [PATCH] updated with improved webpack loader --- README.md | 19 +++++++++++++++++++ webpack_loader/templatetags/webpack_loader.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 6f2f03ca..45b944d8 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,25 @@ if not DEBUG: }) ``` +## Different production and development chunks + +If webpack produces a vendor, manifest etc. file which are required in +the production config but are not produced in the dev environment, use +templatetags as below: + +`django template.html` +```HTML+Django +{% load render_bundle render_bundle_pass_exceptions from webpack_loader %} + + +
+ {% render_bundle_pass_exceptions 'manifest' %} + {% render_bundle_pass_exceptions 'vendor' %} + {% render_bundle 'app' %} + + +``` +

diff --git a/webpack_loader/templatetags/webpack_loader.py b/webpack_loader/templatetags/webpack_loader.py index d1e87ce7..a274cf96 100644 --- a/webpack_loader/templatetags/webpack_loader.py +++ b/webpack_loader/templatetags/webpack_loader.py @@ -3,6 +3,9 @@ from django.utils.safestring import mark_safe from .. import utils +from ..exceptions import ( + WebpackBundleLookupError +) register = template.Library() @@ -12,6 +15,18 @@ def render_bundle(bundle_name, extension=None, config='DEFAULT', attrs=''): tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs) return mark_safe('\n'.join(tags)) +@register.simple_tag +def render_bundle_pass_exceptions(bundle_name, extension=None, config='DEFAULT', attrs=''): + try: + tags = utils.get_as_tags( + bundle_name, + extension=extension, + config=config, + attrs=attrs, + ) + return mark_safe('\n'.join(tags)) + except WebpackBundleLookupError: + return mark_safe("" % bundle_name) @register.simple_tag def webpack_static(asset_name, config='DEFAULT'):