Skip to content

Commit

Permalink
Handle Nuxt SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed Nov 6, 2024
1 parent c50443b commit 8950376
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 51 deletions.
111 changes: 60 additions & 51 deletions integrations/vite/nuxt.test.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,74 @@
import { expect } from 'vitest'
import { candidate, css, fetchStyles, html, json, retryAssertion, test, ts } from '../utils'

test(
'dev mode',
{
fs: {
'package.json': json`
{
"type": "module",
"dependencies": {
"@tailwindcss/vite": "workspace:^",
"nuxt": "^3.13.1",
"tailwindcss": "workspace:^",
"vue": "latest"
}
const SETUP = {
fs: {
'package.json': json`
{
"type": "module",
"dependencies": {
"@tailwindcss/vite": "workspace:^",
"nuxt": "^3.13.1",
"tailwindcss": "workspace:^",
"vue": "latest"
}
`,
'nuxt.config.ts': ts`
import tailwindcss from '@tailwindcss/vite'
}
`,
'nuxt.config.ts': ts`
import tailwindcss from '@tailwindcss/vite'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
vite: {
plugins: [tailwindcss()],
},
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
vite: {
plugins: [tailwindcss()],
},
css: ['~/assets/css/main.css'],
devtools: { enabled: true },
compatibilityDate: '2024-08-30',
})
`,
'app.vue': html`
css: ['~/assets/css/main.css'],
devtools: { enabled: true },
compatibilityDate: '2024-08-30',
})
`,
'app.vue': html`
<template>
<div class="underline">Hello world!</div>
</template>
<div class="underline">Hello world!</div>
</template>
`,
'assets/css/main.css': css`@import 'tailwindcss';`,
},
'assets/css/main.css': css`@import 'tailwindcss';`,
},
async ({ fs, spawn, getFreePort }) => {
let port = await getFreePort()
await spawn(`pnpm nuxt dev --port ${port}`)
}

test('dev mode', SETUP, async ({ fs, spawn, getFreePort }) => {
let port = await getFreePort()
await spawn(`pnpm nuxt dev --port ${port}`)

await retryAssertion(async () => {
let css = await fetchStyles(port)
expect(css).toContain(candidate`underline`)
})
await retryAssertion(async () => {
let css = await fetchStyles(port)
expect(css).toContain(candidate`underline`)
})

await retryAssertion(async () => {
await fs.write(
'app.vue',
html`
await retryAssertion(async () => {
await fs.write(
'app.vue',
html`
<template>
<div class="underline font-bold">Hello world!</div>
</template>
<div class="underline font-bold">Hello world!</div>
</template>
`,
)
)

let css = await fetchStyles(port)
expect(css).toContain(candidate`underline`)
expect(css).toContain(candidate`font-bold`)
})
},
)
let css = await fetchStyles(port)
expect(css).toContain(candidate`underline`)
expect(css).toContain(candidate`font-bold`)
})
})

test('build', SETUP, async ({ spawn, getFreePort, exec }) => {
let port = await getFreePort()
await exec(`pnpm nuxt build`)
await spawn(`PORT=${port} pnpm nuxt preview`)

await retryAssertion(async () => {
let css = await fetchStyles(port)
expect(css).toContain(candidate`underline`)
})
})
5 changes: 5 additions & 0 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export default function tailwindcss(): Plugin[] {
plugin.name !== 'vite:vue'
) {
continue
} else if (plugin.name === 'ssr-styles') {
// The Nuxt ssr-styles plugin emits styles from server-side rendered
// components, we can't run it in the `renderStart` phase so we're
// skipping it.
continue
}

let transformHandler =
Expand Down

0 comments on commit 8950376

Please sign in to comment.