Skip to content

Commit 07e8522

Browse files
authored
fix(styles-plugin): fix plugin styles when using Vite and SSR (#46)
* fix(styles-plugin): fix plugin styles when using Vite and SSR * chore: omit `viteSSR` at Nuxt utils styles * chore: include missing `:` in the prefix * chore: update jsdocs
1 parent a91d110 commit 07e8522

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/nuxt-utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface VuetifyNuxtOptions {
2929
directives?: VuetifyDirectivesOptions
3030
components?: VuetifyComponentsOptions
3131
composables?: VuetifyComposablesOptions
32-
styles?: VuetifyStylesOptions
32+
styles?: Omit<VuetifyStylesOptions, 'viteSSR'>
3333
}
3434

3535
export function configureVuetify(nuxt: Nuxt, options: VuetifyNuxtOptions = {}) {

packages/styles-plugin/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ export interface VuetifyStylesOptions {
3333
mode?: true | 'none' | 'source' | {
3434
configFile: string
3535
}
36+
/**
37+
* Whether to use Vite SSR mode.
38+
*
39+
* If set to `true`, the plugin will use the Vite convention to prefix the Vuetify virtual styles.
40+
*
41+
* Enable this flag if you're using Vuetify with Vite and SSR without Nuxt:
42+
* - [vite-ssg](https://github.com/antfu-collective/vite-ssg)
43+
* - [Vitesse template](https://github.com/antfu-collective/vitesse)
44+
* - [îles](https://github.com/ElMassimo/iles)
45+
* - or any other framework/plugin that uses Vite and SSR
46+
*/
47+
viteSSR?: true
3648
}
3749

3850
export function VuetifyStylesVitePlugin(options: VuetifyStylesOptions = {}) {
@@ -42,8 +54,8 @@ export function VuetifyStylesVitePlugin(options: VuetifyStylesOptions = {}) {
4254
let isNone = false
4355
let cssVariables = false
4456
let fileImport = false
45-
const PREFIX = 'vuetify-styles/'
46-
const SSR_PREFIX = `/@${PREFIX}`
57+
const PREFIX = `${options.viteSSR ? 'virtual:' : ''}vuetify-styles/`
58+
const SSR_PREFIX = options.viteSSR ? `\0${PREFIX}` : `/@${PREFIX}`
4759
const resolveCss = resolveCssFactory()
4860
const api = options.registerApi ?? 'modern-compiler'
4961

0 commit comments

Comments
 (0)