vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.34k stars 6.16k forks source link

Support relative base path on dev server #17482

Closed juan-rvty closed 1 month ago

juan-rvty commented 4 months ago

Description

Make

 const config = {
  base: './'
}

supported in the dev server.

Use case:

Our app always runs inside iframes, even during development. This relates to: https://github.com/vitejs/vite/issues/14105 but in my case the uri is not known before hand. Also relates to: https://github.com/vitejs/vite/issues/11142

Suggested solution

Allow relative base path in dev mode.

Alternative

No response

Additional context

No response

Validations

patak-dev commented 4 months ago

Would you create a minimal reproduction of what your use case so we better understand it. Maybe it would be easier to discuss with a PR to show how the implementation looks. But as we stated in the other open issues, the complexity of supporting a relative base during development was too much to justify the feature.

zhangHongEn commented 2 months ago

https://github.com/module-federation/vite/issues/52 This problem also occurs in the module-federation scenario. The host port is 5175, the remote port is 5176, but the remote resource uses / image image

husayt commented 2 months ago

@patak-dev @yyx990803 FYI, there has been a very good progress with Module Federation support for Vite over last month here (check the new-config branch and examples there). Here @zhangHongEn and @gioboa have used recently released Module Federation 2 which is bundler agnostic. So this hopefully will significantly help efforts to get Vite Module Federation support in place. This approach saves us from implementing MF from scratch and offers consistent behaviour across bundlers, which is especially important in case of MF as modules are often built with different bundlers and it is important to have compatible implementation across. Also, RsPack and NextJs are using this approach to get there MF implemented.

Since MF has been one of the few areas where Vite was not up to speed, it will be great to work with them in order to get first class Module federation support in Vite

sapphi-red commented 1 month ago

@zhangHongEn In your case, won't server.origin: 'https://localhost:5176' work?

zhangHongEn commented 1 month ago

@zhangHongEn In your case, won't server.origin: 'https://localhost:5176' work?

server.origin solved my problem

sapphi-red commented 1 month ago

I'm closing this issue as the author has not provided any additional details for a while and the module federation one is covered by server.origin. Feel free to create a new issue with more details if it's still something that is good to have.