astro/packages/integrations/vue/server.js

25 lines
678 B
JavaScript
Raw Permalink Normal View History

import { h, createSSRApp } from 'vue';
import { renderToString } from 'vue/server-renderer';
import StaticHtml from './static-html.js';
2022-08-31 13:44:52 +00:00
import setup from 'virtual:@astrojs/vue/app';
function check(Component) {
return !!Component['ssrRender'];
}
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) });
2022-08-31 13:44:52 +00:00
setup(app)
const html = await renderToString(app);
return { html };
}
export default {
check,
renderToStaticMarkup,
};