mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 21:02:21 +01:00
Chaining the step onto the build script left `vite build` on its own without compression, and only worked because npm ran the chain. A plugin makes it part of the build itself, so there is nothing to bypass. It runs with enforce: post so the service worker vite-plugin-pwa emits is compressed too, and reads its output directory from the resolved config rather than assuming dist. The precache is generated earlier in the build and still lists no .gz entries. Written here rather than taken off the shelf: vite-plugin-compression was last published in 2022, vite-plugin-brotli caps at vite 7, and vite-plugin-compression2 declares no vite 8 support while depending on @rollup/pluginutils, which this rolldown-based build does not use. Node's zlib covers it in one file with no dependency. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDXxq3vAxJVGhm1pQuK8V7
23 lines
798 B
Python
23 lines
798 B
Python
"""Assert the frontend precompresses its assets and nginx is set to serve them."""
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
NGINX_CONF = REPO_ROOT / "docker" / "nginx" / "default.conf"
|
|
VITE_CONFIG = REPO_ROOT / "frontend" / "vite.config.js"
|
|
|
|
|
|
def test_nginx_serves_precompressed_assets() -> None:
|
|
assert re.search(
|
|
r"^\s*gzip_static\s+on;", NGINX_CONF.read_text(), re.M
|
|
), "gzip_static is off, so the .gz files the build writes would go unused"
|
|
|
|
|
|
def test_build_precompresses() -> None:
|
|
config = VITE_CONFIG.read_text()
|
|
assert "precompress" in config and re.search(r"\bprecompress\(\)", config), (
|
|
"vite.config.js no longer runs the precompress plugin, so nginx's "
|
|
"gzip_static would have nothing to serve"
|
|
)
|