feat: configurable assets_dir and lockfile_dir for apps sharing a project root

BE
1d ago
+599-32

An app always takes its static files from <root>/assets and persists its frontend package.json and lockfiles in <root>/reflex.lock. Two apps that share a project root, say a dashboard and a static marketing site built from the same repo, each with its own config, therefore step on each other:

  • every build copies the whole assets/ into its frontend, so the small site ships the dashboard's assets (22 MB in our case);
  • every install rewrites reflex.lock/, so building the site replaces the dashboard's committed lockfile with the site's smaller package set, and the next dashboard build changes it back.

.web can already move per app with REFLEX_WEB_WORKDIR; these two directories could not. This PR adds two config fields:

config = rx.Config(
    app_name="website",
    assets_dir=Path("website/assets"),
    lockfile_dir=Path("website/reflex.lock"),
)

Both are relative to the app root (absolute paths work too), default to assets and reflex.lock, take strings as well, and can come from REFLEX_ASSETS_DIR / REFLEX_LOCKFILE_DIR like any config field. assets_dir is used wherever the assets directory was hardcoded: the copy into .web/public, rx.asset (local files and the external/ links of shared ones), local stylesheets in App(stylesheets=...), and reflex rename. lockfile_dir goes through frontend_skeleton.get_root_lockfile_dir(), which the lockfile sync, the npm detection and its messages, the hot reload exclusion and telemetry now use. Nothing changes for an app that sets neither.

This touches the same lines of _compile_root_stylesheet as #8007 (page stylesheets), which moves them into helpers; whichever merges second resolves the conflict by reading get_config().assets_dir in those helpers.