UNPKG

rwsdk

Version:

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

24 lines (23 loc) 707 B
import MagicString from "magic-string"; export const injectVitePreamble = ({ clientEntryPathnames, }) => ({ name: "rwsdk:inject-vite-preamble", apply: "serve", transform(code, id) { if (this.environment.name !== "client") { return; } if (!clientEntryPathnames.includes(id)) { return; } // Only inject preamble in development mode if (process.env.NODE_ENV !== "development") { return; } const s = new MagicString(code); s.prepend(`import 'virtual:vite-preamble';\n`); return { code: s.toString(), map: s.generateMap({ hires: true }), }; }, });