Skip to content

public directory is not copied when building twice with write: false and then write: true #22305

@hi-ogawa

Description

@hi-ogawa

Describe the bug

@vitejs/plugin-rsc uses building same environment instance twice, such as following:

import { defineConfig } from 'vite';

export default defineConfig({
  builder: {
    async buildApp(builder) {
      builder.environments.client.config.build.write = false;
      await builder.build(builder.environments.client);
      builder.environments.client.config.build.write = true;
      await builder.build(builder.environments.client);
    },
  },
});

Since Vite 8.0.9, this doesn't copy public directory on second build.

This specific behavior only hits unconventional rsc examples, so this isn't critical, but just reporting it here if anyone has an idea where this is expected, whether this should be avoided, etc.

This behavior change was found in vitejs/vite-plugin-react#1198

Reproduction

https://stackblitz.com/edit/vitejs-vite-2gdu7zbt?file=vite.config.ts

Steps to reproduce

  • open stackblitz
  • run vite build
  • see there's no dist/favicon.svg

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 22.22.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^8.0.10 => 8.0.10

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: buildp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions