vite-plugin-vue-inspector icon indicating copy to clipboard operation
vite-plugin-vue-inspector copied to clipboard

feat: respect vite base path

Open wvffle opened this issue 3 years ago • 4 comments

In some cases when a project stays behind a reverse proxy, the base path needs to be respected when importing virtual modules. This PR fixes that.

wvffle avatar Jul 25 '22 11:07 wvffle

Is there anything blocking this PR?

wvffle avatar Aug 17 '22 20:08 wvffle

Can you provide a use case about it ? Thanks!

webfansplz avatar Aug 22 '22 15:08 webfansplz

Can you provide a use case about it ? Thanks!

Sure, in a project I am working on, we're using vite with --base /front/ flag on both production and development. It's due to our environment structure.

Our reverse proxy is configured to redirect / to a special backend route and redirect /front/* to the vite server when in development mode. This special backend route renders our frontend app served through vite and does some additional magic.

So basically, vite uses /front/ but is accessed through /. Vue inspector fails to recognize that it should serve its scripts through /front/ and it serves them through /, throwing 404 for us. Since this behavior can be fixed in the plugin itself rather than adding an exception to our reverse proxy configuration, I decided to fix it there :)

wvffle avatar Aug 22 '22 16:08 wvffle

Some of the base resolving code is based on vite PWA plugin's code.

I've created similar pull request that got merged in their repo: https://github.com/antfu/vite-plugin-pwa/pull/345

wvffle avatar Aug 22 '22 16:08 wvffle

@webfansplz, do you have more questions regarding the usecase? What's your view on merging this PR?

wvffle avatar Nov 25 '22 20:11 wvffle

@webfansplz, do you have more questions regarding the usecase? What's your view on merging this PR?

I'm not sure if this change will affect any other use cases, and I prefer to simply provide an option for the user to configure

webfansplz avatar Nov 27 '22 14:11 webfansplz

Is there a point in configuring something twice?

wvffle avatar Nov 28 '22 08:11 wvffle

Is there a point in configuring something twice?

The root cause is that we are not quite sure if (! base.match(/^(? :[a-z]+:)? \/\//i) && ! base.startsWith('/') && ! base.startsWith('./')) { will these judge have an impact on other use cases, we need to ensure that they are as flexible and generic as possible.

webfansplz avatar Nov 28 '22 08:11 webfansplz