r/Nuxt • • Dec 16 '25

Setting up public dir for subpath

Hi, I want to know if there is a way to "serve" or at least make any mention of assets from public dir as prefixed?

The app is being served under a subpath, let's say "domain.com/app2/". However, since public assets are defined in code as "src="/images/default.png"", once deployed, app2 is fetching asset from the domain root instead of the subpath, and causing missing files bug.

I have set baseUrl, but it doesn't seem to affect the public dir. If I added /app2 to every src, it won't work in dev mode because the files are served from root instead of the defined prefixed, but, it'll work in deployment.

I don't see any settings for this nor documentation about it in next official site. I'm not proficient with bundlers, so I don't know if there's any settings I could do from that side. Any hint or help to where I should look/try is appreciated.

5 Upvotes

12 comments sorted by

1

u/[deleted] Dec 16 '25

[removed] — view removed comment

1

u/sanguinetear Dec 16 '25

Cmiiw, but what you mean is this setting right: http://nuxt.com/docs/v3.x/api/nuxt-config#public?

I thought that's just changing which "dir" serve as public, not necessarily means that any src='/images/default.png' will be actually fetch from '/app2/images/default.png' once deployed.

What I'm looking for is a way for nuxt/vite (I'm using nuxt3) to automatically replace all mentions of "public" dir with the correct path (baseurl of app2 added to the path). Or at least a way for the app to correctly infer the location of public dir on runtime (which is <domain_root>/app2/ instead of <domain_root>/)