You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
public should be relative to the rootDir instead of srcDir #1209
Currently, publicDir is relative to srcDir, meaning when srcDir is set to 'src', public files must be placed in src/public. This feels unintuitive since public assets typically live at the root level in most web projects.
Having public assets in src/ creates cognitive overhead since:
Most developers expect public files to be at the root level.
It breaks convention with other popular frameworks/tools.
Static assets conceptually don't belong with source code.
Is your feature request related to a bug?
N/A
What are the alternatives?
Make publicDir relative to rootDir instead of srcDir, allowing the public directory to be placed at root level (e.g., <rootDir>/<publicDir>) while source files are organized in src/.
Additional context
This aligns with conventions from other popular web frameworks (Vue, React, Nextjs etc.) where public assets are typically placed at the root level for better project organization and clarity.
changed the title [-]public should be located in the root dir even with srcDir set[/-][+]public should be relative to the rootDir instead of srcDir[/+]on Nov 26, 2024
WXT is inspired by Nuxt, and follows its conventions when it makes sense. Nuxt 3's public directory was relative to the srcDir. That is why WXT's has also always been relative to its srcDir. The 0.4/0.5 changes were me thinking I had read their docs wrong, but then realizing that no, I was right public was inside srcDir, so I reverted the change.
Nuxt 4 plans on changing the public directory to be relative to the root directory. However in their case, it's to extract common code out of the new app and server directories, to which public files belong to both. Read more about their decision here:
One more thing worth noting is Nuxt also moved their modules directory out of the srcDir and made it relative to root as well. If we decide to move the public directory, we should also move the modules directory.
So the real question is if we think the same justification Nuxt has for moving the public directory applies to WXT as well...
I don't think it does, but I agree with you that it better aligns with the conventions across other frameworks... Which might be enough of a reason.
If others vote to change this, it should be added to the upcoming 0.20 release.
Main concern is that WXT isn't a typical "web framework" because extensions are so different, so if there's an exception to the public directory convention in the root of a project, WXT likely falls into that exception
The public directory of an extension is a little weird, in that the files aren't "publicly available" throughout the entire extension, because they're not added to web_accessible_resources by default. There were comments around whether "public" was the right term, but we kinda decided the naming was fine as-is
Overall, people are fine with moving it to the root directory by default, a few concerned about whether or not changing it at this point is worth a breaking change to all existing projects using WXT, if it provides enough value.
But since I'm the executive decision maker... I think we should change it to align with the convention. Even if it doesn't perfectly match the standard definition of a "public" directory, there's still lots of value in onboarding new developers by using familiar terms and concepts.
Main concern is that WXT isn't a typical "web framework" because extensions are so different, so if there's an exception to the public directory convention in the root of a project, WXT likely falls into that exception
The public directory of an extension is a little weird, in that the files aren't "publicly available" throughout the entire extension, because they're not added to web_accessible_resources by default.
This sounds sensible as well, though it would need some documentation.
It would be good with either approach. thank you for your hard work!
Activity
[-]public should be located in the root dir even with srcDir set[/-][+]public should be relative to the rootDir instead of srcDir[/+]2wheeh commentedon Nov 26, 2024
and the comments (jsDoc), it is
"${config.root}/public"instead of"${config.srcDir}/public".2wheeh commentedon Nov 26, 2024
I found this updated and reverted. was there any side effect?
aklinker1 commentedon Nov 26, 2024
WXT is inspired by Nuxt, and follows its conventions when it makes sense. Nuxt 3's
publicdirectory was relative to thesrcDir. That is why WXT's has also always been relative to itssrcDir. The 0.4/0.5 changes were me thinking I had read their docs wrong, but then realizing that no, I was rightpublicwas insidesrcDir, so I reverted the change.Nuxt 4 plans on changing the
publicdirectory to be relative to therootdirectory. However in their case, it's to extract common code out of the newappandserverdirectories, to which public files belong to both. Read more about their decision here:nuxt/nuxt#26444
One more thing worth noting is Nuxt also moved their
modulesdirectory out of thesrcDirand made it relative torootas well. If we decide to move thepublicdirectory, we should also move themodulesdirectory.So the real question is if we think the same justification Nuxt has for moving the
publicdirectory applies to WXT as well...I don't think it does, but I agree with you that it better aligns with the conventions across other frameworks... Which might be enough of a reason.
If others vote to change this, it should be added to the upcoming 0.20 release.
aklinker1 commentedon Nov 26, 2024
@2wheeh could you add links to other framework docs that indicate that the public directory is in the root directory by default?
2wheeh commentedon Nov 26, 2024
@aklinker1
I'm not familiar with Nuxt and didn't consider WXT was based on Nuxt. That's my bad.
I believe many users decide to use WXT since it is based on Vite.
And
create-vitetemplates havesrc/,public/at the root:https://github.com/vitejs/vite/tree/main/packages/create-vite
These are others that I've experienced locating public at the root:
https://nextjs.org/docs/app/getting-started/project-structure
https://docs.astro.build/en/basics/project-structure/#directories-and-files
hope this helps.
aklinker1 commentedon Nov 26, 2024
No worries, I don't expect people to know that lol. Just providing context for further discussion.
There was a conversation around this on discord. To summarize it's main points:
publicdirectory convention in the root of a project, WXT likely falls into that exceptionweb_accessible_resourcesby default. There were comments around whether "public" was the right term, but we kinda decided the naming was fine as-isBut since I'm the executive decision maker... I think we should change it to align with the convention. Even if it doesn't perfectly match the standard definition of a "public" directory, there's still lots of value in onboarding new developers by using familiar terms and concepts.
So I'll add this to 0.20.
2wheeh commentedon Nov 27, 2024
This sounds sensible as well, though it would need some documentation.
It would be good with either approach. thank you for your hard work!
pavi2410 commentedon Dec 8, 2024
Late to the voting, but this was the first change I made when I started using WXT.
aklinker1 commentedon Mar 28, 2025
Released in v0.20.0