|
1 | 1 | import type * as Vite from "vite"; |
2 | 2 | import { init as initEsModuleLexer } from "es-module-lexer"; |
| 3 | +import * as Path from "pathe"; |
3 | 4 | import * as babel from "@babel/core"; |
4 | 5 | import colors from "picocolors"; |
5 | 6 |
|
@@ -28,14 +29,23 @@ import { warnOnClientSourceMaps } from "../plugins/warn-on-client-source-maps"; |
28 | 29 |
|
29 | 30 | export function reactRouterRSCVitePlugin(): Vite.PluginOption[] { |
30 | 31 | let configLoader: ConfigLoader; |
31 | | - let config: ResolvedReactRouterConfig; |
32 | 32 | let typegenWatcherPromise: Promise<Typegen.Watcher> | undefined; |
33 | 33 | let viteCommand: Vite.ConfigEnv["command"]; |
34 | 34 | let routeIdByFile: Map<string, string> | undefined; |
35 | 35 | let logger: Vite.Logger; |
36 | 36 |
|
37 | 37 | const defaultEntries = getDefaultEntries(); |
38 | 38 |
|
| 39 | + let config: ResolvedReactRouterConfig; |
| 40 | + let rootRouteFile: string; |
| 41 | + function updateConfig(newConfig: ResolvedReactRouterConfig) { |
| 42 | + config = newConfig; |
| 43 | + rootRouteFile = Path.resolve( |
| 44 | + newConfig.appDirectory, |
| 45 | + newConfig.routes.root.file, |
| 46 | + ); |
| 47 | + } |
| 48 | + |
39 | 49 | return [ |
40 | 50 | { |
41 | 51 | name: "react-router/rsc", |
@@ -75,7 +85,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] { |
75 | 85 |
|
76 | 86 | const configResult = await configLoader.getConfig(); |
77 | 87 | if (!configResult.ok) throw new Error(configResult.error); |
78 | | - config = configResult.value; |
| 88 | + updateConfig(configResult.value); |
79 | 89 |
|
80 | 90 | if ( |
81 | 91 | viteUserConfig.base && |
@@ -246,7 +256,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] { |
246 | 256 | }); |
247 | 257 |
|
248 | 258 | // Update shared plugin config reference |
249 | | - config = result.value; |
| 259 | + updateConfig(result.value); |
250 | 260 |
|
251 | 261 | if (configChanged || routeConfigChanged) { |
252 | 262 | invalidateVirtualModules(viteDevServer); |
@@ -315,7 +325,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] { |
315 | 325 | id, |
316 | 326 | viteCommand, |
317 | 327 | routeIdByFile, |
318 | | - rootRouteFile: config.unstable_rootRouteFile, |
| 328 | + rootRouteFile, |
319 | 329 | viteEnvironment: this.environment, |
320 | 330 | }); |
321 | 331 | }, |
|
0 commit comments