Skip to content

Commit

Permalink
fix(nuxt): fix runtime toggling w/ nuxt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Feb 7, 2023
1 parent af9b075 commit 5dcacfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineNuxtConfig({
pinceau: {
followSymbolicLinks: false,
configFileName: 'tokens.config',
runtime: false,
},
typescript: {
includeWorkspace: true,
Expand Down
16 changes: 5 additions & 11 deletions src/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,20 @@ const module: any = defineNuxtModule<PinceauOptions>({
// Support runtime features
if (options.runtime) {
lines.push(
'import fs from \'node:fs\'',
'import { dirname, join } from \'pathe\'',
'import { useRuntimeConfig } from \'#imports\'',
'import { plugin as pinceau } from \'pinceau/runtime\'',
'import utils from \'#build/pinceau/utils\'',
'import theme from \'#build/pinceau/index\'',
'',
`export default defineNuxtPlugin(async (nuxtApp) => {
// Setup plugin
nuxtApp.vueApp.use(pinceau, { colorSchemeMode: '${options.colorSchemeMode}', theme, utils })
const { pinceau: runtimeConfig } = useRuntimeConfig()
// Handle first render of SSR styles
nuxtApp.hook('app:rendered', async (app) => {
// Init
app.ssrContext.event.pinceauContent = app.ssrContext.event.pinceauContent || {}
// Runtime styling
const content = app.ssrContext.nuxt.vueApp.config.globalProperties.$pinceauSsr.get()
app.ssrContext.event.pinceauContent.runtime = content
})
Expand All @@ -227,15 +222,14 @@ const module: any = defineNuxtModule<PinceauOptions>({
lines.push(
'import { plugin as pinceau } from \'pinceau/runtime\'',
'import utils from \'#build/pinceau/utils\'',
'',
`export default defineNuxtPlugin(async (nuxtApp) => {
// Setup plugin
nuxtApp.vueApp.use(pinceau, { colorSchemeMode: '${options.colorSchemeMode}', utils })
})`,
`export default defineNuxtPlugin(async (nuxtApp) => nuxtApp.vueApp.use(pinceau, { colorSchemeMode: '${options.colorSchemeMode}', utils }))`,
)
}
else {
lines.push('import \'pinceau.css\'')
lines.push(
'import \'pinceau.css\'',
'export default defineNuxtPlugin(() => {})',
)
}

// Support any reset from @unocss/reset
Expand Down

0 comments on commit 5dcacfe

Please sign in to comment.