%global _empty_manifest_terminate_build 0 Name: python-django-vite Version: 2.1.2 Release: 1 Summary: Integration of ViteJS in a Django project. License: Apache License, Version 2.0 URL: https://github.com/MrBin99/django-vite Source0: https://mirrors.aliyun.com/pypi/web/packages/ba/fa/f811d91d48630f6563ab03b6418eb5a3a5e78e0a44aa91b00ced7374c718/django-vite-2.1.2.tar.gz BuildArch: noarch Requires: python3-Django Requires: python3-black Requires: python3-flake8 %description # Django Vite [![PyPI version](https://badge.fury.io/py/django-vite.svg)](https://badge.fury.io/py/django-vite) Integration of [ViteJS](https://vitejs.dev/) in a Django project. ## Installation ### Django ``` pip install django-vite ``` Add `django_vite` to your `INSTALLED_APPS` in your `settings.py` (before your apps that are using it). ```python INSTALLED_APPS = [ ... 'django_vite', ... ] ``` ### ViteJS Follow instructions on [https://vitejs.dev/guide/](https://vitejs.dev/guide/). And mostly the SSR part. Then in your ViteJS config file : - Set the `base` options the same as your `STATIC_URL` Django setting. - Set the `build.outDir` path to where you want the assets to compiled. - Set the `build.manifest` options to `true`. - As you are in SSR and not in SPA, you don't have an `index.html` that ViteJS can use to determine which files to compile. You need to tell it directly. In your ViteJS config file add the following : ```javascript export default defineConfig({ build { ... rollupOptions: { input: { : '' } } } } ``` ### Assets As recommended on Vite's [backend integration guide](https://vitejs.dev/guide/backend-integration.html), your assets should include the modulepreload polyfill. ```javascript // Add this at the beginning of your app entry. import 'vite/modulepreload-polyfill'; ``` ## Usage ### Configuration - Define a setting variable in your `settings.py` named `DJANGO_VITE_ASSETS_PATH` containing the absolute path to where your assets are built. - This must correspond to your `build.outDir` in your ViteJS configuration. - The `DJANGO_VITE_ASSETS_PATH` must be included in your `STATICFILES_DIRS` Django setting. - Define a setting variable in your `settings.py` named `DJANGO_VITE_DEV_MODE` containing a boolean defining if you want to include assets in development mode or production mode. - In development mode, assets are included as modules using the ViteJS webserver. This will enable HMR for your assets. - In production mode, assets are included as standard assets (no ViteJS webserver and HMR) like default Django static files. This means that your assets must be compiled with ViteJS before. - This setting may be set as the same value as your `DEBUG` setting in Django. But you can do what is good for your needs. Note : `DJANGO_VITE_ASSETS_PATH` supports `pathlib.Path` syntax or pure `str`. ### Template tags Include this in your base HTML template file. ``` {% load django_vite %} ``` Then in your `` element add this : ``` {% vite_hmr_client %} ``` - This will add a `