Fixed #5945 - CSS not Server Side Rendered with PrimeVue 4 / Nuxt 3
parent
f40130a74c
commit
be18995c42
|
@ -80,9 +80,10 @@
|
|||
"changelogen": "^0.5.5",
|
||||
"nitropack": "^2.6.3",
|
||||
"nuxt": "3.3.2",
|
||||
"vitest": "^1.6.0"
|
||||
"vitest": "^1.6.0",
|
||||
"@primevue/themes": "workspace:*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.11.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// @ts-ignore
|
||||
import Aura from '@primevue/themes/aura';
|
||||
|
||||
export default defineNuxtConfig({
|
||||
modules: ['../src/module'],
|
||||
primevue: {
|
||||
|
@ -5,6 +8,9 @@ export default defineNuxtConfig({
|
|||
options: {
|
||||
// ripple, inputStyle etc.
|
||||
ripple: true,
|
||||
theme: {
|
||||
preset: Aura
|
||||
},
|
||||
pt: {
|
||||
panel: {
|
||||
header: 'my-panel-header'
|
||||
|
|
|
@ -48,7 +48,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||
const resolver = createResolver(import.meta.url);
|
||||
const registered = register(moduleOptions);
|
||||
const { autoImport, importPT, importTheme, options } = moduleOptions;
|
||||
const hasTheme = importTheme && !options?.unstyled;
|
||||
const hasTheme = (importTheme || options?.theme) && !options?.unstyled;
|
||||
|
||||
nuxt.options.runtimeConfig.public.primevue = {
|
||||
...moduleOptions,
|
||||
|
@ -87,14 +87,19 @@ export default defineNuxtModule<ModuleOptions>({
|
|||
const uniqueRegisteredStyles = Array.from(new Map(registeredStyles?.map((m: MetaType) => [m.name, m])).values());
|
||||
|
||||
return `
|
||||
import { useRuntimeConfig } from '#imports';
|
||||
${uniqueRegisteredStyles?.map((style: MetaType) => `import ${style.as} from '${style.from}';`).join('\n')}
|
||||
${
|
||||
hasTheme
|
||||
? `import { Theme } from '@primeuix/styled';
|
||||
import ${importTheme.as} from '${normalize(importTheme.from)}';\n`
|
||||
${importTheme ? `import ${importTheme.as} from '${normalize(importTheme.from)}';\n` : ''}`
|
||||
: ''
|
||||
}
|
||||
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const config = runtimeConfig?.public?.primevue ?? {};
|
||||
const { options = {} } = config;
|
||||
|
||||
const stylesToTop = [${registered.injectStylesAsStringToTop.join('')}].join('');
|
||||
const styleProps = {
|
||||
${options?.csp?.nonce ? `nonce: ${options?.csp?.nonce}` : ''}
|
||||
|
@ -104,7 +109,7 @@ const styles = [
|
|||
${uniqueRegisteredStyles?.map((item: MetaType) => `${item.as} && ${item.as}.getStyleSheet ? ${item.as}.getStyleSheet(undefined, styleProps) : ''`).join(',')}
|
||||
].join('');
|
||||
|
||||
${hasTheme ? `Theme.setTheme(${importTheme.as})` : ''}
|
||||
${hasTheme ? `Theme.setTheme(${importTheme?.as} || options?.theme)` : ''}
|
||||
|
||||
const themes = [
|
||||
${`${uniqueRegisteredStyles?.[0].as} && ${uniqueRegisteredStyles?.[0].as}.getCommonThemeStyleSheet ? ${uniqueRegisteredStyles?.[0].as}.getCommonThemeStyleSheet(undefined, styleProps) : ''`},
|
||||
|
@ -131,14 +136,14 @@ ${registered.config.map((config: MetaType) => `import ${config.as} from '${confi
|
|||
${registered.services.map((service: MetaType) => `import ${service.as} from '${service.from}';`).join('\n')}
|
||||
${!autoImport && registered.directives.map((directive: MetaType) => `import ${directive.as} from '${directive.from}';`).join('\n')}
|
||||
${importPT ? `import ${importPT.as} from '${normalize(importPT.from)}';\n` : ''}
|
||||
${hasTheme ? `import ${importTheme.as} from '${normalize(importTheme.from)}';\n` : ''}
|
||||
${hasTheme && importTheme ? `import ${importTheme.as} from '${normalize(importTheme.from)}';\n` : ''}
|
||||
|
||||
export default defineNuxtPlugin(({ vueApp }) => {
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const config = runtimeConfig?.public?.primevue ?? {};
|
||||
const { usePrimeVue = true, options = {} } = config;
|
||||
const pt = ${importPT ? `{ pt: ${importPT.as} }` : `{}`};
|
||||
const theme = ${hasTheme ? `{ theme: ${importTheme.as} }` : `{}`};
|
||||
const theme = ${hasTheme ? `{ theme: ${importTheme?.as} || options?.theme }` : `{}`};
|
||||
|
||||
usePrimeVue && vueApp.use(PrimeVue, { ...options, ...pt, ...theme });
|
||||
${registered.services.map((service: MetaType) => `vueApp.use(${service.as});`).join('\n')}
|
||||
|
|
947
pnpm-lock.yaml
947
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue