UNPKG

htmelt

Version:

Bundle your HTML assets with Esbuild and LightningCSS. Custom plugins, HMR platform, and more.

25 lines (24 loc) 784 B
// src/client/cssReload.ts var cssReload_default = async (file) => { const url = new URL(file, import.meta.env.DEV_URL); const prevLink = document.querySelector(`link[href^="${url.href}"]`); if (prevLink) { console.info("[HMR] css updated:", url.href); const link = document.createElement("link"); link.rel = "stylesheet"; link.href = url.href + "?t=" + Date.now(); link.onload = () => prevLink.remove(); prevLink.after(link); } else { const style = document.querySelector(`style[data-href^="${url.href}"]`); if (style) { console.info("[HMR] css updated:", url.href); style.textContent = await fetch(url.href, { cache: "no-store" }).then( (res) => res.text() ); } } }; export { cssReload_default as default };