Files
imen_pishghaman/apps/web/app/plugins/antd-style.ts
T

23 lines
669 B
TypeScript
Raw Normal View History

import { createCache, extractStyle } from "ant-design-vue";
/**
* Ant Design Vue uses CSS-in-JS. During SSR/SSG we collect the generated styles into a cache
* and inline them into <head>, so prerendered HTML is fully styled before hydration (no FOUC).
*/
export default defineNuxtPlugin((nuxtApp) => {
const cache = createCache();
if (import.meta.server) {
nuxtApp.hook("app:rendered", ({ ssrContext }) => {
const css = extractStyle(cache, true);
if (css && ssrContext) {
ssrContext.head.push({
style: [{ key: "antd-cssinjs", innerHTML: css }],
});
}
});
}
return { provide: { antdCache: cache } };
});