Skip to content

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

Description

@2wheeh

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.

Activity

  1. reopened this on Nov 26, 2024
  2. 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
  3. 2wheeh commented on Nov 26, 2024

    @2wheeh
    Author

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

  4. 2wheeh commented on Nov 26, 2024

    @2wheeh
    Author
    ## 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?

  5. aklinker1 commented on Nov 26, 2024

    @aklinker1
    Member

    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.

  6. aklinker1 commented on Nov 26, 2024

    @aklinker1
    Member

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

  7. 2wheeh commented on Nov 26, 2024

    @2wheeh
    Author

    @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.

  8. aklinker1 commented on Nov 26, 2024

    @aklinker1
    Member

    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.

  9. 2wheeh commented on Nov 27, 2024

    @2wheeh
    Author

    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!

  10. pavi2410 commented on Dec 8, 2024

    @pavi2410

    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.

  11. aklinker1 commented on Mar 28, 2025

    @aklinker1
    Member

    Released in v0.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions