Skip to content

build --watch doesn't watch files in public #18655

Open
@Skn0tt

Description

@Skn0tt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions