@@ -14,6 +14,7 @@ const loadConfig = loadConfigC12<Partial<TWConfig>>
1414type ResolvedConfig = ResolvedC12Config < Partial < TWConfig > >
1515
1616const pagesContentPath = getContext < string [ ] > ( 'twcss-pages-path' )
17+ const componentsContentPath = getContext < string [ ] > ( 'twcss-components-path' )
1718const resolvedConfigsCtx = getContext < Array < ResolvedConfig | null > > ( 'twcss-resolved-configs' )
1819
1920const createInternalContext = async ( moduleOptions : ModuleOptions , nuxt = useNuxt ( ) ) => {
@@ -80,7 +81,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
8081 if ( ! isLayer ) {
8182 const pageFiles = pagesContentPath . tryUse ( )
8283
83- if ( pageFiles && pageFiles . length ) {
84+ if ( moduleOptions . experimental ?. strictScanContentPaths && pageFiles && pageFiles . length ) {
8485 // replace filenames like [...path].vue with ?...path?.vue because [ and ] are reserved in glob matching
8586 rootProjectFiles . push ( ...pageFiles . map ( p => p . replaceAll ( / \[ ( \. + ) ( [ ^ . ] .* ) \] / g, '?$1$2?' ) ) )
8687 }
@@ -90,21 +91,32 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
9091 }
9192 }
9293
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+
93115 return {
94116 config : {
95117 content : {
96118 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 ,
108120 nuxtOptions . dir ?. layouts && withSrcDir ( `${ nuxtOptions . dir . layouts } /**/*${ sfcExtensions } ` ) ,
109121 nuxtOptions . dir ?. plugins && withSrcDir ( `${ nuxtOptions . dir . plugins } /**/*${ defaultExtensions } ` ) ,
110122 ...importDirs . map ( d => `${ d } /**/*${ defaultExtensions } ` ) ,
@@ -241,14 +253,28 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
241253 }
242254 } )
243255
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 )
246259
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+ }
252278
253279 nuxt . hook ( 'vite:serverCreated' , ( server ) => {
254280 nuxt . hook ( 'tailwindcss:internal:regenerateTemplates' , ( data ) => {
0 commit comments