Feature Request: option for publicDir to override the default public root in dev mode
See original GitHub issueIs your feature request related to a problem? Please describe.
Currently, even though publicDir
is set to a directory inside vite.config.js
, in addition to serving those files statically, all files in the current directory are also still served as static files in dev mode.
For example, http://localhost:3000/package.json will always show the project’s package.json
regardless of the publicDir
.
Describe the solution you’d like
One of:
- Disable the “default root is always public” behavior when the
publicDir
is set (is this a breaking change?) - An option in the config to disable the “root is public” behavior, if the above is not feasible.
Additional context
Some devs have tripped up and accidentally referenced /public/image.png
in their code, which works in dev but breaks in production, as the project root is no longer served as static.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Shared Options | Vite
Specifying this in config will override the default mode for both serve and build. This value can also be overridden via the command...
Read more >Public Path - webpack
Public Path. The publicPath configuration option can be quite useful in a variety of scenarios. It allows you to specify the base path...
Read more >Batch migrate Exchange Server public folders to Microsoft 365 ...
Public folder mailbox growth in Exchange Online is managed using an auto-split feature that splits the public folder mailbox when it exceeds ...
Read more >How to Override Symfony's default Directory Structure
By default, the .env configuration file is located at the root directory ... You also need to change the extra.public-dir option in the...
Read more >Serving static assets in webpack dev server - Stack Overflow
I would add that it was the opposite for me. I originally had my images and .obj/.mtl files in a public folder that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What’s the rationale for this being a feature that the dev server currently works differently than production in this way? I was actually just coming here to report a bug when a member of my team imported some assets from the root directory instead of putting them in “public”, which would have caused it to break in production had I not caught it.
Nope. That’s a typo in the commit message, they intended to close #2857, not this issue. Reopening.