feat: generate/link source map files for JS and CSS

This commit is contained in:
David Larlet 2024-01-19 09:22:09 -05:00
parent 4541578b9b
commit df3ed76f3e
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD

View file

@ -222,10 +222,18 @@ class UmapManifestStaticFilesStorage(ManifestStaticFilesStorage):
for original_path, processed_path, processed in collected: for original_path, processed_path, processed in collected:
if processed_path.endswith(".js"): if processed_path.endswith(".js"):
path = Path(settings.STATIC_ROOT) / processed_path path = Path(settings.STATIC_ROOT) / processed_path
minified = jsmin(path.read_text()) initial = path.read_text()
path_map = path.with_suffix(f"{path.suffix}.map")
minified = jsmin(initial)
minified += f"\n//# sourceMappingURL={path_map.name}"
path.write_text(minified) path.write_text(minified)
path_map.write_text(initial)
if processed_path.endswith(".css"): if processed_path.endswith(".css"):
path = Path(settings.STATIC_ROOT) / processed_path path = Path(settings.STATIC_ROOT) / processed_path
minified = cssmin(path.read_text()) initial = path.read_text()
path_map = path.with_suffix(f"{path.suffix}.map")
minified = cssmin(initial)
minified += f"\n//# sourceMappingURL={path_map.name}"
path.write_text(minified) path.write_text(minified)
path_map.write_text(initial)
yield original_path, processed_path, True yield original_path, processed_path, True