1
1
import { existsSync } from 'fs'
2
2
import { join , relative } from 'pathe'
3
- import defu , { defuArrayFn } from 'defu'
3
+ import { defuArrayFn } from 'defu'
4
+ import { watch } from 'chokidar'
4
5
import chalk from 'chalk'
5
6
import consola from 'consola'
6
7
import {
@@ -100,7 +101,10 @@ export default defineNuxtModule<ModuleOptions>({
100
101
cwd : string
101
102
}
102
103
103
- for ( const layer of ( nuxt . options . _layers as NuxtLayer [ ] ) ) {
104
+ // nuxt.options._layers is from rootDir to nested level
105
+ // We need to reverse the order to give the deepest tailwind.config the lowest priority
106
+ const layers = ( nuxt . options . _layers as NuxtLayer [ ] ) . slice ( ) . reverse ( )
107
+ for ( const layer of layers ) {
104
108
await addConfigPath ( layer ?. config ?. tailwindcss ?. configPath || join ( layer . cwd , 'tailwind.config' ) )
105
109
contentPaths . push ( ...layerPaths ( layer . cwd ) )
106
110
}
@@ -111,15 +115,24 @@ export default defineNuxtModule<ModuleOptions>({
111
115
112
116
// Watch the Tailwind config file to restart the server
113
117
if ( nuxt . options . dev ) {
114
- // @ts -ignore
115
- nuxt . options . watch = nuxt . options . watch || [ ]
116
- // @ts -ignore
117
- configPaths . forEach ( path => nuxt . options . watch . push ( path ) )
118
+ if ( isNuxt2 ( ) ) {
119
+ // @ts -ignore
120
+ nuxt . options . watch = nuxt . options . watch || [ ]
121
+ // @ts -ignore
122
+ configPaths . forEach ( path => nuxt . options . watch . push ( path ) )
123
+ } else {
124
+ watch ( configPaths ) . on ( 'change' , ( path ) => {
125
+ logger . info ( `Tailwind config changed: ${ path } ` )
126
+ logger . warn ( 'Please restart the Nuxt server to apply changes' )
127
+ } )
128
+ }
118
129
}
119
130
120
131
// Default tailwind config
121
132
let tailwindConfig : any = defuArrayFn ( moduleOptions . config , { content : contentPaths } )
122
133
// Recursively resolve each config and merge tailwind configs together.
134
+ console . log ( configPaths )
135
+ // The config
123
136
for ( const configPath of configPaths ) {
124
137
let _tailwindConfig
125
138
try {
@@ -136,6 +149,7 @@ export default defineNuxtModule<ModuleOptions>({
136
149
tailwindConfig = defuArrayFn ( _tailwindConfig , tailwindConfig )
137
150
}
138
151
}
152
+ console . log ( ( tailwindConfig . theme . extend . colors ) )
139
153
140
154
// Write cjs version of config to support vscode extension
141
155
const resolveConfig : any = await import ( 'tailwindcss/resolveConfig.js' ) . then ( r => r . default || r )
0 commit comments