UNPKG

@astro-utils/forms

Version:

Server component for Astro (call server functions from client side with validation and state management)

30 lines (29 loc) 1.17 kB
import { writeFile } from "fs/promises"; import { refactorCodeInlineRenderComponent } from "./integration/codeTransform.js"; export default { name: '@astro-utils/forms', hooks: { 'astro:config:setup'({ config, command }) { var _a; if (!command) return; config.vite ?? (config.vite = {}); (_a = config.vite).plugins ?? (_a.plugins = []); config.vite.plugins.push({ name: 'astro-utils-dev', async transform(code, id) { if (code.includes('class RenderTemplateResult')) { code = refactorCodeInlineRenderComponent(code); if (id.includes("/node_modules/astro/")) { await writeFile(id, code); } } if (id.endsWith('node_modules/vite/dist/client/client.mjs')) { return code.replace(/\blocation\.reload\(\)(([\s;])|\b)/g, "window.open(location.href, '_self')$1"); } return code; } }); } } };