-
Couldn't load subscription status.
- Fork 340
Description
I tried to see if I need to use 'django-webpack-loader' but still not convinced. Its objective is to allow use of the generated webpack bundles, but this can be achieved easily with 'html-webpack-plugin' which generates an html file with the bundle files injected in it, this html file then can be used as a django template.
The advantage of using 'html-webpack-plugin' becomes more obvious when using a pre-configured webpack ecosystem (like vue cli) where we get a ready made html file with all the needed head/body bundle tags (including prefetch/preload links ...) injected, without any need to manually select what to put in head/body.
Here is my setup (simplified):
base.html
{% block html %} <!DOCTYPE html> <html {% block html_tag_attributes %}{% endblock %}> <head> {% block head %} <meta charset="utf-8"> {% endblock %} </head> <body {% block body_tag_attributes %}{% endblock %}> {% block body %} {% block content %}{% endblock %} {% endblock %} </body> </html> {% endblock %}index.html (template used by html-webpack-plugin to generate bundles/webpack/home_page.html):
{% extends "base.html" %} {% load static %} {% block html %} <!DOCTYPE html> <html {% block html_tag_attributes %}{{ block.super }}{% endblock %}> <head> {% block head %}{{ block.super }}{% endblock %} </head> <body {% block body_tag_attributes %}{{ block.super }}{% endblock %}> {% block body %}{{ block.super }}{% endblock %} </body> </html> {% endblock %}home_page.html
{% extends "bundles/webpack/home_page.html" %} {% block content %} Adding content here... {% endblock %}I appreciate if someone can tell if there is a scenario where we can do it only with django-webpack-loader
Note: the links in the injected tags can be easily converted to django static tempate tag format, ie: 'bundles/js/main.js' ==> {% static 'bundles/js/main.js' %}
I created a minimal basic plugin to do this: https://gitlab.com/noor-projects/django-static-webpack-plugin/blob/master/index.js