Skip to content

Commit c448158

Browse files
committedJan 14, 2025·
fix: check for non-resolved tailwind.config
1 parent ae83c7a commit c448158

File tree

8 files changed

+68
-58
lines changed

8 files changed

+68
-58
lines changed
 

‎docs/app/components/AppHeader.vue

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ const { header } = useAppConfig()
1111
<template #logo>
1212
<TheLogo class="h-6" />
1313
<TailwindText class="h-4" />
14-
<UTooltip v-if="header.pkgVersion" :text="`Latest release: v${header.pkgVersion}`">
15-
<UBadge variant="subtle" size="xs" class="-mb-[2px] rounded font-semibold">
16-
v{{ header.pkgVersion.match(/[0-9]+\.[0-9]+/)[0] }}
17-
</UBadge>
18-
</UTooltip>
14+
<UTooltip
15+
v-if="header.pkgVersion"
16+
:text="`Latest release: v${header.pkgVersion}`"
17+
>
18+
<UBadge
19+
variant="subtle"
20+
size="xs"
21+
class="-mb-[2px] rounded font-semibold"
22+
>
23+
v{{ header.pkgVersion.match(/[0-9]+\.[0-9]+/)[0] }}
24+
</UBadge>
25+
</UTooltip>
1926
</template>
2027

2128
<template

‎docs/app/components/TailwindText.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 377.44 55.32">
2+
<svg
3+
xmlns="http://www.w3.org/2000/svg"
4+
viewBox="0 0 377.44 55.32"
5+
>
36
<path
47
fill="currentColor"
58
d="M24.12,24.87H14.89V42.73c0,4.77,3.13,4.69,9.23,4.4v7.22C11.76,55.84,6.85,52.41,6.85,42.73V24.87H0V17.12H6.85v-10l8-2.38V17.12h9.23Zm35.19-7.75h8V54.35h-8V49c-2.83,3.94-7.22,6.33-13,6.33-10.12,0-18.53-8.57-18.53-19.58s8.41-19.58,18.54-19.58c5.8,0,10.2,2.38,13,6.25ZM47.55,47.65A11.5,11.5,0,0,0,59.31,35.74,11.5,11.5,0,0,0,47.55,23.83,11.5,11.5,0,0,0,35.79,35.74,11.5,11.5,0,0,0,47.55,47.65ZM80.76,11.54A5.2,5.2,0,0,1,75.62,6.4a5.14,5.14,0,1,1,10.27,0A5.19,5.19,0,0,1,80.76,11.54Zm-4,42.81V17.12h8V54.35Zm17.34,0V0h8V54.35Zm60.23-37.23h8.49L151.11,54.35h-7.89l-7.75-25.09-7.81,25.09h-7.89L108.08,17.12h8.49l7.22,25.69,7.81-25.69h7.67L147,42.81Zm18.47-5.58a5.2,5.2,0,0,1-5.14-5.14,5.14,5.14,0,1,1,10.27,0A5.19,5.19,0,0,1,172.78,11.54Zm-4,42.81V17.12h8V54.35Zm36.92-38.2c8.34,0,14.3,5.66,14.3,15.34V54.35h-8v-22c0-5.66-3.28-8.63-8.34-8.63-5.29,0-9.46,3.12-9.46,10.72v20h-8V17.12h8v4.77c2.46-3.87,6.48-5.74,11.54-5.74ZM258.1,2.23h8V54.35h-8V49c-2.83,3.94-7.23,6.33-13,6.33-10.13,0-18.54-8.57-18.54-19.58s8.41-19.58,18.54-19.58c5.8,0,10.2,2.38,13,6.25ZM246.33,47.65a11.5,11.5,0,0,0,11.76-11.91,11.76,11.76,0,1,0-23.52,0A11.5,11.5,0,0,0,246.33,47.65Zm46.76,7.67a19.26,19.26,0,0,1-19.66-19.58,19.2,19.2,0,0,1,19.66-19.58,18.39,18.39,0,0,1,16.6,9.6l-6.93,4c-1.63-3.5-5.28-5.73-9.75-5.73a11.36,11.36,0,0,0-11.54,11.69A11.35,11.35,0,0,0,293,47.42a10.9,10.9,0,0,0,9.9-5.73l6.93,4a18.73,18.73,0,0,1-16.75,9.68Zm30-27.92c0,6.77,20,2.68,20,16.45,0,7.45-6.48,11.47-14.52,11.47-7.45,0-12.81-3.35-15.19-8.71l6.92-4c1.2,3.35,4.17,5.36,8.27,5.36,3.57,0,6.33-1.19,6.33-4.17,0-6.63-20-2.91-20-16.23,0-7,6-11.39,13.62-11.39,6.11,0,11.17,2.83,13.78,7.74l-6.78,3.8a7.25,7.25,0,0,0-7-4.25c-2.9,0-5.43,1.27-5.43,3.95Zm34.32,0c0,6.77,20,2.68,20,16.45,0,7.45-6.48,11.47-14.52,11.47-7.45,0-12.81-3.35-15.19-8.71l6.92-4c1.2,3.35,4.17,5.36,8.27,5.36,3.57,0,6.33-1.19,6.33-4.17,0-6.63-20-2.91-20-16.23,0-7,6-11.39,13.62-11.39C369,16.16,374,19,376.62,23.9l-6.78,3.8a7.24,7.24,0,0,0-7-4.25c-2.91,0-5.44,1.27-5.44,3.95Z"

‎docs/app/components/content/Sandbox.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
const props = defineProps({
3-
src: { type: String, default: 'main' }
3+
src: { type: String, default: 'main' },
44
})
55
66
const colorMode = useColorMode()
@@ -16,7 +16,7 @@ const colorMode = useColorMode()
1616
class="w-full h-full min-h-[700px] overflow-hidden bg-gray-100 dark:bg-gray-800"
1717
/>
1818
</div>
19-
19+
2020
<span class="text-sm text-gray-500 dark:text-gray-400">
2121
Open in <NuxtLink
2222
:to="`https://github.com/nuxt-modules/tailwindcss/tree/${props.src}`"

‎docs/nuxt.config.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,29 @@ export default defineNuxtConfig({
1010
'@nuxthq/studio',
1111
'nuxt-og-image',
1212
],
13+
// Devtools / Typescript
14+
devtools: { enabled: true },
1315
ui: {
1416
icons: ['heroicons', 'simple-icons', 'ph'],
1517
},
18+
alias: {
19+
'@nuxtjs/tailwindcss': '../src/module',
20+
},
21+
routeRules: {
22+
'/getting-started': { redirect: '/getting-started/installation' },
23+
'/tailwind': { redirect: '/tailwind/config' },
24+
'/examples': { redirect: '/examples/basic' },
25+
'/api/search.json': { prerender: true },
26+
},
27+
future: { compatibilityVersion: 4 },
28+
29+
compatibilityDate: '2024-07-11',
30+
nitro: {
31+
prerender: {
32+
routes: ['/'],
33+
},
34+
},
35+
typescript: { strict: false },
1636
// Fonts
1737
fontMetrics: {
1838
fonts: ['DM Sans'],
@@ -24,24 +44,4 @@ export default defineNuxtConfig({
2444
'DM+Sans': [400, 500, 600, 700],
2545
},
2646
},
27-
nitro: {
28-
prerender: {
29-
routes: ['/'],
30-
},
31-
},
32-
routeRules: {
33-
'/getting-started': { redirect: '/getting-started/installation' },
34-
'/tailwind': { redirect: '/tailwind/config' },
35-
'/examples': { redirect: '/examples/basic' },
36-
'/api/search.json': { prerender: true },
37-
},
38-
// Devtools / Typescript
39-
devtools: { enabled: true },
40-
typescript: { strict: false },
41-
alias: {
42-
'@nuxtjs/tailwindcss': '../src/module',
43-
},
44-
45-
compatibilityDate: '2024-07-11',
46-
future: { compatibilityVersion: 4 },
4747
})

‎playground/modules/resolved.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export default defineNuxtModule({
1212
oldConfig
1313
? setTimeout(() => updateTemplates({ filter: t => t.filename === 'resolved-config.cjs' }), 100)
1414
: addTemplate({
15-
filename: 'resolved-config.cjs',
16-
getContents: () => `module.exports = /* ${counter++}, ${Boolean(oldConfig)} */ ${JSON.stringify(config, null, 2)}`,
17-
write: true,
18-
}),
15+
filename: 'resolved-config.cjs',
16+
getContents: () => `module.exports = /* ${counter++}, ${Boolean(oldConfig)} */ ${JSON.stringify(config, null, 2)}`,
17+
write: true,
18+
}),
1919
)
2020

2121
// const template = addTemplate({

‎playground/nuxt.config.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ export default defineNuxtConfig({
1717
'@nuxt/content',
1818
],
1919

20-
tailwindcss: {
21-
// viewer: false,
22-
config: {},
23-
exposeConfig: true,
24-
cssPath: '~/assets/css/tailwind.css',
25-
editorSupport: true,
26-
} satisfies Partial<ModuleOptions>,
20+
css: [
21+
// Including Inter CSS is the first component to reproduce HMR issue. It also causes playground to look better,
22+
// since Inter is a native font for Tailwind UI
23+
'@fontsource/inter/400.css',
24+
'@fontsource/inter/500.css',
25+
'@fontsource/inter/600.css',
26+
'@fontsource/inter/700.css',
27+
],
28+
29+
content: {
30+
documentDriven: true,
31+
},
32+
33+
compatibilityDate: '2024-07-11',
2734

2835
hooks: {
2936
'tailwindcss:loadConfig': (config, configPath, idx) => {
@@ -61,18 +68,11 @@ export default defineNuxtConfig({
6168
},
6269
} satisfies Partial<ModuleHooks>,
6370

64-
content: {
65-
documentDriven: true,
66-
},
67-
68-
css: [
69-
// Including Inter CSS is the first component to reproduce HMR issue. It also causes playground to look better,
70-
// since Inter is a native font for Tailwind UI
71-
'@fontsource/inter/400.css',
72-
'@fontsource/inter/500.css',
73-
'@fontsource/inter/600.css',
74-
'@fontsource/inter/700.css',
75-
],
76-
77-
compatibilityDate: '2024-07-11',
71+
tailwindcss: {
72+
// viewer: false,
73+
config: {},
74+
exposeConfig: true,
75+
cssPath: '~/assets/css/tailwind.css',
76+
editorSupport: true,
77+
} satisfies Partial<ModuleOptions>,
7878
})

‎src/internal-context/load.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
108108
const thenCallHook = async (resolvedConfig: ResolvedConfig) => {
109109
const { configFile: resolvedConfigFile } = resolvedConfig
110110
if (!resolvedConfigFile || !resolvedConfig.config) {
111-
return resolvedConfig
111+
return { ...resolvedConfig, configFile: resolvedConfigFile === 'tailwind.config' ? undefined : resolvedConfigFile }
112112
}
113113

114114
const config = configMerger(undefined, resolvedConfig.config)
@@ -170,7 +170,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
170170
(_, v) => typeof v === 'function' ? `() => (${JSON.stringify(v())})` : v,
171171
).replace(/"(\(\) => \(.*\))"/g, (_, substr) => substr.replace(/\\"/g, '"'))
172172

173-
const layerConfigs = resolvedConfigsCtx.use().map((c, idx): [string | null, string | null] => c?.configFile ? [`import cfg${idx} from ${JSON.stringify(/[/\\]node_modules[/\\]/.test(c.configFile) ? c.configFile : './' + relative(targetDir, c.configFile))}`, configUpdatedHook[c.configFile] ? `(() => {const cfg=configMerger(undefined, cfg${idx});${configUpdatedHook[c.configFile]};return cfg;})()` : `cfg${idx}`] : [null, c && serializeConfig(c.config)])
173+
const layerConfigs = resolvedConfigsCtx.use().map((c, idx): [string | null, string | null] => c?.configFile ? [`import cfg${idx} from ${JSON.stringify(/[/\\]node_modules[/\\]/.test(c.configFile) ? c.configFile : './' + relative(targetDir, c.configFile))}`, configUpdatedHook[c.configFile] ? `(() => {const cfg=configMerger(undefined, cfg${idx});${configUpdatedHook[c.configFile]};return cfg;})()` : `cfg${idx}`] : [null, c?.config ? serializeConfig(c.config) : null])
174174

175175
return [
176176
`// generated by the @nuxtjs/tailwindcss <https://github.com/nuxt-modules/tailwindcss> module at ${(new Date()).toLocaleString()}`,

‎test/fixtures/basic/nuxt.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { resolve } from 'node:path'
22

33
export default defineNuxtConfig({
4-
alias: {
5-
'@nuxtjs/tailwindcss': resolve(__dirname, '../../../src/module.ts'),
6-
},
74
modules: [
85
'@nuxtjs/tailwindcss',
96
],
7+
alias: {
8+
'@nuxtjs/tailwindcss': resolve(__dirname, '../../../src/module.ts'),
9+
},
1010
})

0 commit comments

Comments
 (0)
Please sign in to comment.