# django-webpack-pages
[![PyPI version](https://badge.fury.io/py/django-webpack-pages.svg)](https://pypi.org/project/django-webpack-pages/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Use webpack with your multi-page, multi-lingual django webapp.
This project is based on [django-webpack-loader](https://pypi.org/project/django-webpack-loader/)
which handles the connection to webpack.
Consider using [webpack-critical-pages](https://www.npmjs.com/package/webpack-critical-pages) as well
if you are interested in speedups.
Put the following in your settings file:
```python
WEBPACK_PAGES = {
"CRITICAL_CSS_ENABLED": True,
"ROOT_PAGE_DIR": osp.join(BASE_DIR, "pages"),
"STATICFILE_BUNDLES_BASE": "bundles/{locale}/", # should end in /
}
STATICFILES_FINDERS = (
"webpack_pages.pageassetfinder.PageAssetFinder",
# ... and more of your choosing:
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
# configure the loaded page directories and add the WebpackExtension
TEMPLATES = [
{
"BACKEND": "django_jinja.backend.Jinja2",
"DIRS": [osp.join(BASE_DIR, "templates"), osp.join(BASE_DIR, "pages")]
+ [osp.join(BASE_DIR, app, "pages") for app in GRAZBALL_APPS]
+ [osp.join(BASE_DIR, app, "components") for app in GRAZBALL_APPS],
"APP_DIRS": True,
"OPTIONS": {
# ...
"extensions": [
# ...
"webpack_pages.jinja2ext.WebpackExtension",
],
}
}
]
```
Using `webpack_loader.contrib.pages` you can register entrypoints for corresponding pages in templates.
At the top of your individual page, do:
```jinja2
{% extends "layout.jinja" %}
{% do register_entrypoint("myapp/dashboard") %}
```
In the layout's (base template's) head, place the following:
```jinja2
<!DOCTYPE html>
{% do register_entrypoint("main") %}
<html lang="{{ LANGUAGE_CODE }}">
<head>
...
{{ render_css() }}
</head>
<body>
...
{{ render_js() }}
</body>
```
This will load the registered entrypoints in order (`main`, then `myapp/dashboard`) and automatically inject
the webpack-generated css and js. It also supports critical css injection upon first request visits.
Raw data
{
"_id": null,
"home_page": "https://github.com/MrP01/django-webpack-pages",
"name": "django-webpack-pages",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "django, webpack, assets",
"author": "MrP01",
"author_email": "peter@waldert.at",
"download_url": "https://files.pythonhosted.org/packages/15/00/ce9efbe4df37e6665e8e77e92ff0f2c8365250f54233926aa9b58045fd68/django_webpack_pages-0.1.6.tar.gz",
"platform": null,
"description": "# django-webpack-pages\n\n[![PyPI version](https://badge.fury.io/py/django-webpack-pages.svg)](https://pypi.org/project/django-webpack-pages/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nUse webpack with your multi-page, multi-lingual django webapp.\n\nThis project is based on [django-webpack-loader](https://pypi.org/project/django-webpack-loader/)\nwhich handles the connection to webpack.\nConsider using [webpack-critical-pages](https://www.npmjs.com/package/webpack-critical-pages) as well\nif you are interested in speedups.\n\nPut the following in your settings file:\n\n```python\nWEBPACK_PAGES = {\n \"CRITICAL_CSS_ENABLED\": True,\n \"ROOT_PAGE_DIR\": osp.join(BASE_DIR, \"pages\"),\n \"STATICFILE_BUNDLES_BASE\": \"bundles/{locale}/\", # should end in /\n}\n\nSTATICFILES_FINDERS = (\n \"webpack_pages.pageassetfinder.PageAssetFinder\",\n # ... and more of your choosing:\n \"django.contrib.staticfiles.finders.FileSystemFinder\",\n \"django.contrib.staticfiles.finders.AppDirectoriesFinder\",\n)\n\n# configure the loaded page directories and add the WebpackExtension\nTEMPLATES = [\n {\n \"BACKEND\": \"django_jinja.backend.Jinja2\",\n \"DIRS\": [osp.join(BASE_DIR, \"templates\"), osp.join(BASE_DIR, \"pages\")]\n + [osp.join(BASE_DIR, app, \"pages\") for app in GRAZBALL_APPS]\n + [osp.join(BASE_DIR, app, \"components\") for app in GRAZBALL_APPS],\n \"APP_DIRS\": True,\n \"OPTIONS\": {\n # ...\n \"extensions\": [\n # ...\n \"webpack_pages.jinja2ext.WebpackExtension\",\n ],\n }\n }\n]\n```\n\nUsing `webpack_loader.contrib.pages` you can register entrypoints for corresponding pages in templates.\n\nAt the top of your individual page, do:\n\n```jinja2\n{% extends \"layout.jinja\" %}\n{% do register_entrypoint(\"myapp/dashboard\") %}\n```\n\nIn the layout's (base template's) head, place the following:\n\n```jinja2\n<!DOCTYPE html>\n{% do register_entrypoint(\"main\") %}\n<html lang=\"{{ LANGUAGE_CODE }}\">\n<head>\n ...\n {{ render_css() }}\n</head>\n<body>\n ...\n {{ render_js() }}\n</body>\n```\n\nThis will load the registered entrypoints in order (`main`, then `myapp/dashboard`) and automatically inject\nthe webpack-generated css and js. It also supports critical css injection upon first request visits.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Use webpack with your multi-page, multi-lingual django webapp",
"version": "0.1.6",
"project_urls": {
"Homepage": "https://github.com/MrP01/django-webpack-pages"
},
"split_keywords": [
"django",
" webpack",
" assets"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "166c5758bf832014d769475129277e6e1b9c9e28aca2eb48d6d4a32e599e9be2",
"md5": "afe03e17d5240b6380e85fa013b8160e",
"sha256": "2c32bd6648bb263822f69bf2434f082c1844e619a1d0bda82302d555fc5d9e6f"
},
"downloads": -1,
"filename": "django_webpack_pages-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "afe03e17d5240b6380e85fa013b8160e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 6289,
"upload_time": "2024-05-24T17:28:07",
"upload_time_iso_8601": "2024-05-24T17:28:07.717425Z",
"url": "https://files.pythonhosted.org/packages/16/6c/5758bf832014d769475129277e6e1b9c9e28aca2eb48d6d4a32e599e9be2/django_webpack_pages-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1500ce9efbe4df37e6665e8e77e92ff0f2c8365250f54233926aa9b58045fd68",
"md5": "009dbb7ea45d79dc0efdf9e1edfbc79d",
"sha256": "f74ec4e283147c5557b22f060a4c542f612fd89dcbfc502653c550708edc14ef"
},
"downloads": -1,
"filename": "django_webpack_pages-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "009dbb7ea45d79dc0efdf9e1edfbc79d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 5220,
"upload_time": "2024-05-24T17:28:08",
"upload_time_iso_8601": "2024-05-24T17:28:08.801186Z",
"url": "https://files.pythonhosted.org/packages/15/00/ce9efbe4df37e6665e8e77e92ff0f2c8365250f54233926aa9b58045fd68/django_webpack_pages-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-24 17:28:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MrP01",
"github_project": "django-webpack-pages",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-webpack-pages"
}