import type { Plugin } from 'vite' ; import { isBoolean } from 'lodash' ; import { all } from 'deepmerge' ; import * as history from 'connect-history-api-fallback' ; see https export const serverHistoryPlugin = ( opt ) : Plugin => { if ( isBoolean ( opt ) ) return null ; return { name : 'vite-plugin-server-history' , enforce : 'pre' , configureServer ( { middlewares : app } ) { const handler = history ( all ( [ opt , { rewrites : [ { from : /.*/ , to : ( ctx ) => ctx . parsedUrl . pathname } ] } ] ) ) ; app . use ( handler ) ; } , } ; } ;