-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: OPTIC-1061: Improve webpack bundle management so bundles can b…
…e cached more effectively (#6797)
- Loading branch information
Showing
6 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
from django.conf import settings | ||
|
||
# Load manifest.json once at module scope | ||
_MANIFEST = {} | ||
try: | ||
if not settings.DEBUG: | ||
manifest_path = Path(settings.STATIC_ROOT) / 'js/manifest.json' | ||
if manifest_path.exists(): | ||
with open(manifest_path, 'r') as f: | ||
_MANIFEST = json.load(f) | ||
except Exception: | ||
# If there's any error reading the manifest, we'll use the default mapping | ||
pass | ||
|
||
|
||
def get_manifest_asset(path: str) -> str: | ||
"""Maps a path to its hashed filename using manifest.json, or falls back to /react-app/ prefix | ||
Usage in template: | ||
{% manifest_asset 'main.js' %} | ||
""" | ||
if path in _MANIFEST: | ||
return f'{settings.FRONTEND_HOSTNAME}{_MANIFEST[path]}' | ||
return f'{settings.FRONTEND_HOSTNAME}/react-app/{path}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters