fix(map): import leaflet CSS statically so Vite emits the file

Dynamic await import of CSS only emits a JS shim (leaflet-src.HASH.js)
that injects styles at runtime, but the actual stylesheet file
(leaflet.HASH.css) is never written to dist/_astro/, causing 404s
on Astro's preload helper.

Static top-level import is processed at build time and emits the CSS.
Lazy-loading is preserved: the component still hydrates only with
client:media="(min-width: 900px)" in index.astro.
This commit is contained in:
2026-07-25 14:23:31 +02:00
parent 8c68703f2c
commit b711069fe0
+1 -1
View File
@@ -1,4 +1,5 @@
import { useEffect, useRef } from 'preact/hooks';
import 'leaflet/dist/leaflet.css';
import type { Aviso } from '../lib/types';
import { municipioCoords } from '../lib/fixtures';
@@ -18,7 +19,6 @@ export default function MapView({ avisos }: Props) {
(async () => {
const L = await import('leaflet');
await import('leaflet/dist/leaflet.css');
if (!mapEl.current) return;
map = L.map(mapEl.current, {