Override urls in dist for local server while keeping live server urls?

I have some html popups in a build which work fine in local builds when referenced by src="/products/resistor-2/index.html" but once the build is on a server, it looks for that full address.

I want to put the live server addresses in either at build time when exported e.g.

On Build >
Append "/products/… with “www.livewebsite.com/” so it is “www.livewebsite.com/products/

Or alternatively, in the actual source html files, I add the full server urls “www.livewebsite.com/products/” but have some rule that while in development or local server only, overwrite that “www.livewebsite.com/” bit with ‘localhost’ or just remove that bit of the line completely locally so local server runs use the local files?

Not sure which is the best approach here

https://stackoverflow.com/questions/68754394/replace-url-during-build-step-of-npm

Original Post on Discord

by user 103054507105067008

Hey Rob, are you sure this is related to Needle Engine?
We won’t be able to give support on each and any regular webdev question :wink:

Could be wrong URLs (usually there’s a . at the beginning), could be wrong setup (vite for example does that automatically - are you using vite here?), could be something else, but it doesn’t sound needle related.

For sure, I might ask about it on stackoverflow, is there any plan to have a section of a forum here just for general web dev chat? I’ve been having a lot of fun working with other Needle devs figuring this stuff out, I understand it isn’t Needle related

by user 103054507105067008

I’m using Vite too so I’ll start looking into what it does there

by user 103054507105067008

We can do that, sure!

Generally vite will keep the relative URLs. If you want a server relative URL, use ./products. If you want a URL relative to your page, use /products.

Have you tried that?

I’ll give that a shot and ping back if it worked, the client’s web designer who gave me the html files didn’t know much about vite either so they set up those urls for sub pages without the . before /products/ and other sub pages

by user 103054507105067008

That’d be brilliant, I had help from other developers here when I was setting up post processing with Needle before too and want to keep sharing the tips and things I find as I use it in projects. I’m also tasked at work to sort out some AR preset move/scale/rotate functionality that I’d like to share to you guys and other devs for samples :+1:

by user 103054507105067008

that’s not related to vite, that’s just how URIs work :slightly_smiling_face:

I can confirm your suggested fix of “./products” instead of “/products” worked, and also “…/…/images” worked for parent folders perfectly too

by user 103054507105067008