0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/vue/server.js

25 lines
725 B
JavaScript
Raw Normal View History

import { h, createSSRApp } from 'vue';
import { renderToString } from 'vue/server-renderer';
2022-10-13 14:17:42 -05:00
import { setup } from 'virtual:@astrojs/vue/app';
import StaticHtml from './static-html.js';
function check(Component) {
return !!Component['ssrRender'] || !!Component['__ssrInlineRender'];
}
async function renderToStaticMarkup(Component, props, slotted) {
const slots = {};
for (const [key, value] of Object.entries(slotted)) {
slots[key] = () => h(StaticHtml, { value, name: key === 'default' ? undefined : key });
}
const app = createSSRApp({ render: () => h(Component, props, slots) });
await setup(app);
const html = await renderToString(app);
return { html };
}
export default {
check,
renderToStaticMarkup,
};