11import path from 'path'
22import defu from 'defu'
3+ import gracefulFs from 'graceful-fs'
34
45import tailwindConfig from './tailwind.config'
56
7+ const fs = gracefulFs . promises
8+
69function themeModule ( ) {
710 // wait for nuxt options to be normalized
811 const { nuxt } = this
@@ -13,11 +16,27 @@ function themeModule () {
1316 // Configure `static/ dir
1417 options . dir . static = path . resolve ( options . rootDir , options . dir . static || 'static' )
1518 // Configure `components/` dir
16- hook ( 'components:dirs' , ( dirs ) => {
17- dirs . push ( {
18- path : path . resolve ( options . rootDir , 'components/global' ) ,
19- global : true
20- } )
19+ hook ( 'components:dirs' , async ( dirs ) => {
20+ const componentsDirPath = path . resolve ( nuxt . options . rootDir , 'components' )
21+ const componentsDirStat = await fs . stat ( componentsDirPath ) . catch ( ( ) => null )
22+ if ( componentsDirStat && componentsDirStat . isDirectory ( ) ) {
23+ dirs . push ( {
24+ path : componentsDirPath
25+ } )
26+ } else {
27+ nuxt . options . watch . push ( componentsDirPath )
28+ }
29+
30+ const globalComponentsDirPath = path . resolve ( nuxt . options . rootDir , 'components/global' )
31+ const globalComponentsDirStat = await fs . stat ( globalComponentsDirPath ) . catch ( ( ) => null )
32+ if ( globalComponentsDirStat && globalComponentsDirStat . isDirectory ( ) ) {
33+ dirs . push ( {
34+ path : globalComponentsDirPath ,
35+ global : true
36+ } )
37+ } else {
38+ nuxt . options . watch . push ( globalComponentsDirPath )
39+ }
2140 } )
2241 // Configure content after each hook
2342 hook ( 'content:file:beforeInsert' , ( document ) => {
0 commit comments