import type { UserConfig } from 'vite' ; import * as path from 'path' ; import reactRefresh from '@vitejs/plugin-react-refresh' ; import mdx from 'vite-plugin-mdx' ; import pages , { DefaultPageStrategy } from 'vite-plugin-react-pages' ; module . exports = { jsx : 'react' , plugins : [ reactRefresh ( ) , mdx ( ) , pages ( { pagesDir : path . join ( __dirname , 'pages' ) , pageStrategy : new DefaultPageStrategy ( { extraFindPages : async ( pagesDir , helpers ) => { const srcPath = path . join ( __dirname , '../src' ) ; if ( String ( process . env . SHOW_ALL_COMPONENT_DEMOS ) === 'true' ) { helpers . watchFiles ( srcPath , '*/demos/**/*.{[tj]sx,md?(x)}' , async function fileHandler ( file , api ) { const { relative , path : absolute } = file ; const match = relative . match ( /(.*)\/demos\/(.*)\.([tj]sx|mdx?)$/ ) ; if ( ! match ) throw new Error ( 'unexpected file: ' + absolute ) ; const [ _ , componentName , demoName ] = match ; const pageId = `/components/demos/${ componentName }` ; const runtimeDataPaths = api . getRuntimeData ( pageId ) ; runtimeDataPaths [ demoName ] = `${ absolute }?demo` ; } ) ; } helpers . watchFiles ( srcPath , '*/README.md?(x)' , async function fileHandler ( file , api ) { const { relative , path : absolute } = file ; const match = relative . match ( /(.*)\/README\.mdx?$/ ) ; if ( ! match ) throw new Error ( 'unexpected file: ' + absolute ) ; const [ _ , componentName ] = match ; const pageId = `/components/${ componentName }` ; const runtimeDataPaths = api . getRuntimeData ( pageId ) ; runtimeDataPaths . main = absolute ; const staticData = api . getStaticData ( pageId ) ; staticData . main = await helpers . extractStaticData ( file ) ; } ) ; } , } ) , } ) , ] , resolve : { alias : { 'my-lib' : path . join ( __dirname , '../src' ) , } , } , } as UserConfig ;