`build --watch` doesn't watch files in `public`

Open
#18,655 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
node.js, typescript

Research direction

Start with the linked minimal reproduction, run npm ci and npx vite build --watch, then edit public/foo and compare it with dist/foo. Trace the build-watch handling for public-directory files and add coverage showing that edits are copied to the output directory without restarting the build.

Written by the indexing model from the issue text.

Description

feat: build p3-downstream-blocker
Describe the bug

It appears that vite build --watch only copies over public once when initialised, instead of watching them. We expect them to be watched just like other source files.

We use Vite to build a website with a service worker into a static directory, so that our custom HTTP server can pick it up. The website has a service worker and it needs different build settings than the main site. We have a separate vite build --watch --outDir=public --config=vite.sw.config.ts process that does that. We expect the main vite build --watch process to watch file changes in public just like it watches file changes from outher sources, and we expect it to sync those changes into its out dir so our custom HTTP server can pick them up.

Reproduction

https://github.com/Skn0tt/vite-build-watch-public-repro

Steps to reproduce
  1. npm ci
  2. npx vite build --watch
  3. edit contents of public/foo

expected: dist/foo contains updated content

actual: dist/foo contains content old content from when npx vite build --watch was started

System Info
System:
    OS: macOS 15.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 125.64 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.7.0 - ~/.nvm/versions/node/v22.7.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.7.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v22.7.0/bin/npm
    pnpm: 9.6.0 - ~/.nvm/versions/node/v22.7.0/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.70
    Edge: 130.0.2849.80
    Safari: 18.1
  npmPackages:
    vite: ^5.4.11 => 5.4.11
Used Package Manager

npm

Logs

No response

Validations
Dominant language
TypeScript
Stars
82.9k
Forks
8.8k
Avg merge
1d 23h
Merged PRs (30d)
61

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vitejs/vite

All issues in vitejs/vite

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.