@@ -350,10 +350,12 @@ async function resolveConfig({
350
350
root,
351
351
viteNodeContext,
352
352
reactRouterConfigFile,
353
+ skipRoutes,
353
354
} : {
354
355
root : string ;
355
356
viteNodeContext : ViteNode . Context ;
356
357
reactRouterConfigFile ?: string ;
358
+ skipRoutes ?: boolean ;
357
359
} ) : Promise < Result < ResolvedReactRouterConfig > > {
358
360
let reactRouterUserConfig : ReactRouterConfig = { } ;
359
361
@@ -499,61 +501,67 @@ async function resolveConfig({
499
501
) ;
500
502
}
501
503
502
- let routes : RouteManifest = {
503
- root : { path : "" , id : "root" , file : rootRouteFile } ,
504
- } ;
504
+ let routes : RouteManifest = { } ;
505
505
506
- let routeConfigFile = findEntry ( appDirectory , "routes" ) ;
506
+ if ( ! skipRoutes ) {
507
+ routes = {
508
+ root : { path : "" , id : "root" , file : rootRouteFile } ,
509
+ } ;
507
510
508
- try {
509
- if ( ! routeConfigFile ) {
510
- let routeConfigDisplayPath = Path . relative (
511
- root ,
512
- Path . join ( appDirectory , "routes.ts" )
513
- ) ;
514
- return err ( `Route config file not found at "${ routeConfigDisplayPath } ".` ) ;
515
- }
511
+ let routeConfigFile = findEntry ( appDirectory , "routes" ) ;
516
512
517
- setAppDirectory ( appDirectory ) ;
518
- let routeConfigExport = (
519
- await viteNodeContext . runner . executeFile (
520
- Path . join ( appDirectory , routeConfigFile )
521
- )
522
- ) . default ;
523
- let routeConfig = await routeConfigExport ;
524
-
525
- let result = validateRouteConfig ( {
526
- routeConfigFile,
527
- routeConfig,
528
- } ) ;
513
+ try {
514
+ if ( ! routeConfigFile ) {
515
+ let routeConfigDisplayPath = Path . relative (
516
+ root ,
517
+ Path . join ( appDirectory , "routes.ts" )
518
+ ) ;
519
+ return err (
520
+ `Route config file not found at "${ routeConfigDisplayPath } ".`
521
+ ) ;
522
+ }
529
523
530
- if ( ! result . valid ) {
531
- return err ( result . message ) ;
532
- }
524
+ setAppDirectory ( appDirectory ) ;
525
+ let routeConfigExport = (
526
+ await viteNodeContext . runner . executeFile (
527
+ Path . join ( appDirectory , routeConfigFile )
528
+ )
529
+ ) . default ;
530
+ let routeConfig = await routeConfigExport ;
531
+
532
+ let result = validateRouteConfig ( {
533
+ routeConfigFile,
534
+ routeConfig,
535
+ } ) ;
533
536
534
- routes = {
535
- ...routes ,
536
- ...configRoutesToRouteManifest ( appDirectory , routeConfig ) ,
537
- } ;
538
- } catch ( error : any ) {
539
- return err (
540
- [
541
- colors . red ( `Route config in "${ routeConfigFile } " is invalid.` ) ,
542
- "" ,
543
- error . loc ?. file && error . loc ?. column && error . frame
544
- ? [
545
- Path . relative ( appDirectory , error . loc . file ) +
546
- ":" +
547
- error . loc . line +
548
- ":" +
549
- error . loc . column ,
550
- error . frame . trim ?.( ) ,
551
- ]
552
- : error . stack ,
553
- ]
554
- . flat ( )
555
- . join ( "\n" )
556
- ) ;
537
+ if ( ! result . valid ) {
538
+ return err ( result . message ) ;
539
+ }
540
+
541
+ routes = {
542
+ ...routes ,
543
+ ...configRoutesToRouteManifest ( appDirectory , routeConfig ) ,
544
+ } ;
545
+ } catch ( error : any ) {
546
+ return err (
547
+ [
548
+ colors . red ( `Route config in "${ routeConfigFile } " is invalid.` ) ,
549
+ "" ,
550
+ error . loc ?. file && error . loc ?. column && error . frame
551
+ ? [
552
+ Path . relative ( appDirectory , error . loc . file ) +
553
+ ":" +
554
+ error . loc . line +
555
+ ":" +
556
+ error . loc . column ,
557
+ error . frame . trim ?.( ) ,
558
+ ]
559
+ : error . stack ,
560
+ ]
561
+ . flat ( )
562
+ . join ( "\n" )
563
+ ) ;
564
+ }
557
565
}
558
566
559
567
let future : FutureConfig = {
@@ -613,10 +621,12 @@ export async function createConfigLoader({
613
621
rootDirectory : root ,
614
622
watch,
615
623
mode,
624
+ skipRoutes,
616
625
} : {
617
626
watch : boolean ;
618
627
rootDirectory ?: string ;
619
628
mode : string ;
629
+ skipRoutes ?: boolean ;
620
630
} ) : Promise < ConfigLoader > {
621
631
root = Path . normalize ( root ?? process . env . REACT_ROUTER_ROOT ?? process . cwd ( ) ) ;
622
632
@@ -641,7 +651,7 @@ export async function createConfigLoader({
641
651
updateReactRouterConfigFile ( ) ;
642
652
643
653
let getConfig = ( ) =>
644
- resolveConfig ( { root, viteNodeContext, reactRouterConfigFile } ) ;
654
+ resolveConfig ( { root, viteNodeContext, reactRouterConfigFile, skipRoutes } ) ;
645
655
646
656
let appDirectory : string ;
647
657
@@ -740,9 +750,11 @@ export async function createConfigLoader({
740
750
filepath
741
751
) ) ;
742
752
743
- let routeConfigFile = findEntry ( appDirectory , "routes" , {
744
- absolute : true ,
745
- } ) ;
753
+ let routeConfigFile = ! skipRoutes
754
+ ? findEntry ( appDirectory , "routes" , {
755
+ absolute : true ,
756
+ } )
757
+ : undefined ;
746
758
let routeConfigCodeChanged =
747
759
routeConfigFile !== undefined &&
748
760
isEntryFileDependency (
@@ -793,13 +805,16 @@ export async function createConfigLoader({
793
805
export async function loadConfig ( {
794
806
rootDirectory,
795
807
mode,
808
+ skipRoutes,
796
809
} : {
797
810
rootDirectory : string ;
798
811
mode : string ;
812
+ skipRoutes ?: boolean ;
799
813
} ) {
800
814
let configLoader = await createConfigLoader ( {
801
815
rootDirectory,
802
816
mode,
817
+ skipRoutes,
803
818
watch : false ,
804
819
} ) ;
805
820
let config = await configLoader . getConfig ( ) ;
0 commit comments