Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

public should be relative to the rootDir instead of srcDir #1209

Open
2wheeh opened this issue Nov 26, 2024 · 8 comments · May be fixed by #1085
Open

public should be relative to the rootDir instead of srcDir #1209

2wheeh opened this issue Nov 26, 2024 · 8 comments · May be fixed by #1085
Labels

Comments

@2wheeh
Copy link

2wheeh commented Nov 26, 2024

Feature Request

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.

@2wheeh 2wheeh added the feature label Nov 26, 2024
@2wheeh 2wheeh closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2024
@2wheeh 2wheeh reopened this Nov 26, 2024
@2wheeh 2wheeh 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 Nov 26, 2024
@2wheeh
Copy link
Author

2wheeh commented Nov 26, 2024

and the comments (jsDoc), it is "${config.root}/public" instead of "${config.srcDir}/public".

@2wheeh
Copy link
Author

2wheeh commented Nov 26, 2024

## v0.4.0 &rarr; v0.5.0
### Revert Move Public Directory
Change default `publicDir` to from `<rootDir>/public` to `<srcDir>/public`.
## v0.3.0 &rarr; v0.4.0
### Update Default Path Aliases
Use relative path aliases inside `.wxt/tsconfig.json`.
## v0.2.0 &rarr; v0.3.0
### Move Public Directory
Change default `publicDir` to from `<srcDir>/public` to `<rootDir>/public`.

I found this updated and reverted. was there any side effect?

@aklinker1
Copy link
Collaborator

aklinker1 commented 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:

nuxt/nuxt#26444

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.

@aklinker1
Copy link
Collaborator

@2wheeh could you add links to other framework docs that indicate that the public directory is in the root directory by default?

@2wheeh
Copy link
Author

2wheeh commented 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-vite templates have src/, 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
Copy link
Collaborator

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:

  1. 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
  2. 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
  3. 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.

So I'll add this to 0.20.

@2wheeh
Copy link
Author

2wheeh commented Nov 27, 2024

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!

@aklinker1 aklinker1 linked a pull request Nov 28, 2024 that will close this issue
15 tasks
@pavi2410
Copy link

pavi2410 commented Dec 8, 2024

If others vote to change this, it should be added to the upcoming 0.20 release.

Late to the voting, but this was the first change I made when I started using WXT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants