UNPKG

@redwoodjs/sdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

23 lines (22 loc) 717 B
import MagicString from "magic-string"; export const injectHmrPreambleJsxPlugin = () => ({ name: "rwsdk:inject-hmr-preamble", apply: "serve", async transform(code, id) { const htmlHeadRE = /jsxDEV\("html",[^]*?jsxDEV\("head",[^]*?\[(.*?)\]/s; const match = code.match(htmlHeadRE); if (!match) { return; } const s = new MagicString(code); const headContentStart = match.index + match[0].lastIndexOf("["); s.appendLeft(headContentStart + 1, `jsxDEV("script", { type: "module", src: "/__vite_preamble__", }),`); return { code: s.toString(), map: s.generateMap(), }; }, });