If your manifest.json is hosted on a remote source like S3, you must subclass DjangoViteAppClient and its ManifestClient to override how the manifest is loaded.
- Implement
S3ManifestClient: Override load_manifest() to fetch the JSON from S3. - Implement
S3DjangoViteAppClient: Set your custom ManifestClient class. - Configure Django: Pass the custom client class to the
app_client_class setting.
# myapp/django_vite_s3.py
import json
import boto3
from django_vite.core.asset_loader import ManifestClient, DjangoViteAppClient
class S3ManifestClient(ManifestClient):
def load_manifest(self):
s3 = boto3.client("s3")
res = s3.get_object(Bucket='your-bucket', Key='manifest.json')
return json.loads(res["Body"].read())
class S3DjangoViteAppClient(DjangoViteAppClient):
ManifestClient = S3ManifestClient
# settings.py
DJANGO_VITE = {
"default": {
"dev_mode": False,
"app_client_class": "myapp.django_vite_s3.S3DjangoViteAppClient",
}
}
class S3ManifestClient(ManifestClient):
def load_manifest(self):
s3 = boto3.client("s3")
res = s3.get_object(Bucket='django-vite-public-example', Key='manifest.json')
manifest_content = res["Body"].read()
return json.loads(manifest_content)
class S3DjangoViteAppClient(DjangoViteAppClient):
ManifestClient = S3ManifestClient