Closed Kinqdos closed 2 months ago
I am not sure process.cwd()
is a good idea. What happens if vite is started from another directory?
I think (but I probably not understand the problem fully) there must be another solution that does not rely on cwd
.
Yeah I see your point. Its the same behavior as the router cli. It searches for routes (and the config file) from the directory you started the cli / vite. This is already the behavior of the route generator. The problem is that the plugin wich handles the hmr updates always takes the vite root directory as "starting" point. (vite root is the directory with the index.html)
Another solution would be passing the vite root to the route generator instead of passing a relative directory. But therefore you also have to edit the router generator.
As compromise you could replace the await getConfig(inlineConfig, ROOT)
by await getConfig(inlineConfig, ".")
. This doesnt relies on cwd, but leads to the same result. In addtion you have to replace all join(ROOT, ...)
with just resolve(...)
.
"edit the router generator " in which way?
Because the generator function exported by the router-generator only takes the userConfig as argument. So you have to add the root directory as argument
i see no problem with this additional change, can you update the PR?
Yes I can do! My concern is, that other packages wich also depend on the generator
function, will break with the changes to the arguments.
P.S: The getConfig
function from the router-generator also relies on cwd as fallback:
export async function getConfig(
inlineConfig: Partial<Config> = {},
configDirectory?: string,
): Promise<Config> {
if (configDirectory === undefined) {
configDirectory = process.cwd()
}
...
Any thoughts? Or should I start update the pr?
can't you add the root directory as optional argument, if it is not set, fall back to cwd
?
Just thinking if it is good to change the behavior here. The router-generator relies on cwd why can't the vite plugin? With passing the root to the generator we are introducing a different behavior between the vite plugin and the cli. The vite plugin is looking for config in the vite route directory, but if you switch over to using the cli nothing will work. The cli is looking for the config in the cwd and not in the vite root. So you have to move your config from the vite root to the cwd and update the paths in the config.
Is this a better solution than keeping the cwd solution in the vite-plugin?
ok, let's merge this, and wait for complaints :)
CI is running/has finished running commands for commit dd1faa992bc3e1431b2e928d5c0baa24f58eb7ca. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this CI Pipeline Execution
Sent with 💌 from NxCloud.
Fixes issue #1240