1
1
import replace from '@rollup/plugin-replace' ;
2
2
import * as Vite from 'vite' ;
3
+ import { join } from 'node:path' ;
3
4
import { placeholder } from './basename.js' ;
4
5
import { DEFAULT_OUTPUT_DIR_PATH , build } from './build.js' ;
5
6
import { ReactRouterPluginContext } from './types.js' ;
@@ -32,7 +33,7 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
32
33
}
33
34
34
35
async function reloadCtx ( ) {
35
- const config = await reactRouterPlugin . config ( viteUserConfig , viteConfigEnv ) ;
36
+ const config = await reactRouterPlugin . config ( viteUserConfig , { ... viteConfigEnv , command : 'build' } ) ;
36
37
ctx = extractReactRouterPluginContext ( config ) ;
37
38
}
38
39
@@ -43,7 +44,6 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
43
44
viteUserConfig = _viteUserConfig ;
44
45
viteConfigEnv = _viteConfigEnv ;
45
46
if ( ctx && ctx . reactRouterConfig . basename ) {
46
- console . log ( { placeholder, basename : ctx . reactRouterConfig . basename } ) ;
47
47
viteUserConfig . plugins ?. push ( replace . default ( {
48
48
[ placeholder ] : ctx . reactRouterConfig . basename ,
49
49
} ) ) ;
@@ -58,13 +58,15 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
58
58
ctx = extractReactRouterPluginContext ( config ) ;
59
59
generateTypeFile ( ) ;
60
60
} ,
61
- async watchChange ( id , change ) {
62
- if ( ! reactRouterPlugin ) {
61
+ async watchChange ( id ) {
62
+ if ( ! reactRouterPlugin || ! ctx ) {
63
63
return ;
64
64
}
65
- if ( change . event === 'update' ) {
65
+
66
+ if ( ! id . startsWith ( ctx . reactRouterConfig . appDirectory ) ) {
66
67
return ;
67
68
}
69
+
68
70
await reloadCtx ( ) ;
69
71
generateTypeFile ( ) ;
70
72
} ,
0 commit comments