@@ -537,20 +537,19 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
537537 }
538538
539539 let fileContent = await readFile ( join ( sandboxDir , configFile ) , 'utf-8' ) ;
540- // Insert resolve: { preserveSymlinks: true } as a sibling to plugins in the top-level config object
540+
541+ // Insert resolve: { preserveSymlinks: true } and optionally server.fs.allow as siblings to plugins
541542 // Handles both defineConfig({ ... }) and defineWorkspace([ ... , { ... }])
542543 fileContent = fileContent . replace ( / ( p l u g i n s \s * : \s * \[ [ ^ \] ] * \] , ? ) / , ( match ) => {
543- // Insert resolve after plugins
544- return `${ match } \n resolve: {\n preserveSymlinks: true\n },` ;
545- } ) ;
544+ let replacement = `${ match } \n resolve: {\n preserveSymlinks: true\n },` ;
546545
547- // In linked mode, add server.fs.allow to allow Vite to serve files from the monorepo root
548- if ( options . link ) {
549- fileContent = fileContent . replace ( / ( p l u g i n s \s * : \s * \[ [ ^ \] ] * \] , ? ) / , ( match ) => {
550- // Insert server.fs.allow after plugins (alongside resolve)
551- return ` ${ match } \n server: {\n fs: {\n allow: ['../../..']\n }\n },` ;
552- } ) ;
553- }
546+ // In linked mode, also add server.fs.allow to allow Vite to serve files from the monorepo root
547+ if ( options . link ) {
548+ replacement += `\n server: {\n fs: {\n allow: ['../../..']\n }\n },` ;
549+ }
550+
551+ return replacement ;
552+ } ) ;
554553
555554 // search for storybookTest({...}) and place `tags: 'vitest'` into it but tags option doesn't exist yet in the config. Also consider multi line
556555 const storybookTestRegex = / s t o r y b o o k T e s t \( ( \{ [ \s \S ] * ?\} ) \) / g;
0 commit comments