Skip to content

Commit 158e8ae

Browse files
fix(build): copy public directory after building same environment with write=false (#22328)
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent 47071ce commit 158e8ae

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/vite/src/node/__tests__/build.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,29 @@ test('watch rebuild manifest', async (ctx) => {
11871187
`)
11881188
})
11891189

1190+
test('copies public directory after building same environment with write false first', async (ctx) => {
1191+
const root = resolve(dirname, 'fixtures/public-dir-write-false')
1192+
ctx.onTestFinished(() =>
1193+
fsp.rm(resolve(root, 'dist'), { recursive: true, force: true }),
1194+
)
1195+
1196+
const builder = await createBuilder({
1197+
root,
1198+
configFile: false,
1199+
logLevel: 'silent',
1200+
})
1201+
1202+
builder.environments.client.config.build.write = false
1203+
await builder.build(builder.environments.client)
1204+
1205+
builder.environments.client.config.build.write = true
1206+
await builder.build(builder.environments.client)
1207+
1208+
await expect(
1209+
fsp.readFile(resolve(root, 'dist/favicon.svg'), 'utf-8'),
1210+
).resolves.toBe('<svg></svg>')
1211+
})
1212+
11901213
/**
11911214
* for each chunks in output1, if there's a chunk in output2 with the same fileName,
11921215
* ensure that the chunk code is the same. if not, the chunk hash should have changed.

packages/vite/src/node/__tests__/fixtures/public-dir-write-false/index.html

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Loading

packages/vite/src/node/plugins/prepareOutDir.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export function prepareOutDirPlugin(): Plugin {
2020
if (rendered.has(this.environment)) {
2121
return
2222
}
23-
rendered.add(this.environment)
2423

2524
const { config } = this.environment
2625
if (config.build.write) {
26+
rendered.add(this.environment)
2727
const { root, build: options } = config
2828
const resolvedOutDirs = getResolvedOutDirs(
2929
root,

0 commit comments

Comments
 (0)