question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: option for publicDir to override the default public root in dev mode

See original GitHub issue

Is 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:open
  • Created 3 years ago
  • Reactions:11
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dallonfcommented, May 2, 2021

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.

1reaction
GrygrFlzrcommented, Apr 15, 2021

Nope. That’s a typo in the commit message, they intended to close #2857, not this issue. Reopening.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found