@@ -14,6 +14,7 @@ const loadConfig = loadConfigC12<Partial<TWConfig>>
14
14
type ResolvedConfig = ResolvedC12Config < Partial < TWConfig > >
15
15
16
16
const pagesContentPath = getContext < string [ ] > ( 'twcss-pages-path' )
17
+ const componentsContentPath = getContext < string [ ] > ( 'twcss-components-path' )
17
18
const resolvedConfigsCtx = getContext < Array < ResolvedConfig | null > > ( 'twcss-resolved-configs' )
18
19
19
20
const createInternalContext = async ( moduleOptions : ModuleOptions , nuxt = useNuxt ( ) ) => {
@@ -80,7 +81,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
80
81
if ( ! isLayer ) {
81
82
const pageFiles = pagesContentPath . tryUse ( )
82
83
83
- if ( pageFiles && pageFiles . length ) {
84
+ if ( moduleOptions . experimental ?. strictScanContentPaths && pageFiles && pageFiles . length ) {
84
85
// replace filenames like [...path].vue with ?...path?.vue because [ and ] are reserved in glob matching
85
86
rootProjectFiles . push ( ...pageFiles . map ( p => p . replaceAll ( / \[ ( \. + ) ( [ ^ . ] .* ) \] / g, '?$1$2?' ) ) )
86
87
}
@@ -90,21 +91,32 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
90
91
}
91
92
}
92
93
94
+ const componentPaths : string [ ] = [ ]
95
+ const componentFiles = componentsContentPath . tryUse ( )
96
+
97
+ if ( moduleOptions . experimental ?. strictScanContentPaths && componentFiles && componentFiles . length ) {
98
+ if ( ! isLayer ) componentPaths . push ( ...componentFiles )
99
+ }
100
+ else {
101
+ componentPaths . push (
102
+ withSrcDir ( `components/**/*${ sfcExtensions } ` ) ,
103
+ ...( ( ) => {
104
+ if ( nuxtOptions . components ) {
105
+ return ( Array . isArray ( nuxtOptions . components ) ? nuxtOptions . components : typeof nuxtOptions . components === 'boolean' ? [ 'components' ] : ( nuxtOptions . components . dirs || [ ] ) ) . map ( ( d ) => {
106
+ const valueToResolve = typeof d === 'string' ? d : d ?. path
107
+ return valueToResolve ? `${ resolveAlias ( valueToResolve ) } /**/*${ sfcExtensions } ` : ''
108
+ } ) . filter ( Boolean )
109
+ }
110
+ return [ ]
111
+ } ) ( ) ,
112
+ )
113
+ }
114
+
93
115
return {
94
116
config : {
95
117
content : {
96
118
files : [
97
- withSrcDir ( `components/**/*${ sfcExtensions } ` ) ,
98
- ...( ( ) => {
99
- if ( nuxtOptions . components ) {
100
- return ( Array . isArray ( nuxtOptions . components ) ? nuxtOptions . components : typeof nuxtOptions . components === 'boolean' ? [ 'components' ] : ( nuxtOptions . components . dirs || [ ] ) ) . map ( ( d ) => {
101
- const valueToResolve = typeof d === 'string' ? d : d ?. path
102
- return valueToResolve ? `${ resolveAlias ( valueToResolve ) } /**/*${ sfcExtensions } ` : ''
103
- } ) . filter ( Boolean )
104
- }
105
- return [ ]
106
- } ) ( ) ,
107
-
119
+ ...componentPaths ,
108
120
nuxtOptions . dir ?. layouts && withSrcDir ( `${ nuxtOptions . dir . layouts } /**/*${ sfcExtensions } ` ) ,
109
121
nuxtOptions . dir ?. plugins && withSrcDir ( `${ nuxtOptions . dir . plugins } /**/*${ defaultExtensions } ` ) ,
110
122
...importDirs . map ( d => `${ d } /**/*${ defaultExtensions } ` ) ,
@@ -241,14 +253,28 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
241
253
}
242
254
} )
243
255
244
- nuxt . hook ( 'pages:extend' , async ( pages ) => {
245
- const newPageFiles = resolvePageFiles ( pages )
256
+ if ( moduleOptions . experimental ?. strictScanContentPaths ) {
257
+ nuxt . hook ( 'pages:extend' , async ( pages ) => {
258
+ const newPageFiles = resolvePageFiles ( pages )
246
259
247
- if ( newPageFiles . length !== pagesContentPath . tryUse ( ) ?. length ) {
248
- pagesContentPath . set ( newPageFiles , true )
249
- await reloadConfigTemplate ( )
250
- }
251
- } )
260
+ if ( newPageFiles . length !== pagesContentPath . tryUse ( ) ?. length ) {
261
+ pagesContentPath . set ( newPageFiles , true )
262
+ await reloadConfigTemplate ( )
263
+ }
264
+ } )
265
+
266
+ nuxt . hook ( 'components:extend' , async ( components ) => {
267
+ const newComponentFiles = components . map ( c => c . filePath )
268
+
269
+ if ( newComponentFiles . length !== componentsContentPath . tryUse ( ) ?. length ) {
270
+ componentsContentPath . set ( newComponentFiles , true )
271
+ await reloadConfigTemplate ( )
272
+ }
273
+ } )
274
+ }
275
+ else {
276
+ nuxt . hook ( 'pages:extend' , ( ) => reloadConfigTemplate ( ) )
277
+ }
252
278
253
279
nuxt . hook ( 'vite:serverCreated' , ( server ) => {
254
280
nuxt . hook ( 'tailwindcss:internal:regenerateTemplates' , ( data ) => {
0 commit comments