From fc158a2ebddd559798a7d4f8264febafa16236ae Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 8 Dec 2024 18:09:16 +0900 Subject: [PATCH] fix: fix fileModuleIds from multiple entries --- .../src/node/server/environments/rolldown.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/server/environments/rolldown.ts b/packages/vite/src/node/server/environments/rolldown.ts index 222667f8949517..0ce3d989b4a707 100644 --- a/packages/vite/src/node/server/environments/rolldown.ts +++ b/packages/vite/src/node/server/environments/rolldown.ts @@ -279,26 +279,29 @@ class RolldownEnvironment extends DevEnvironment { ...this.inputOptions, output: this.outputOptions, }) - this.result = await this.instance.build() - this.fileModuleIds = new Set( - this.result.output[0].moduleIds.map((id) => cleanUrl(id)), - ) + await this.buildInner() this.buildTimestamp = Date.now() console.timeEnd(`[rolldown:${this.name}:build]`) } + async buildInner() { + this.result = await this.instance.build() + this.fileModuleIds = new Set( + this.result.output + .flatMap((c) => (c.type === 'chunk' ? c.moduleIds : [])) + .map((id) => cleanUrl(id)), + ) + } + async buildHmr( file: string, ): Promise { logger.info(`hmr '${file}'`, { timestamp: true }) console.time(`[rolldown:${this.name}:rebuild]`) - const result = await this.instance.build() - this.fileModuleIds = new Set( - this.result.output[0].moduleIds.map((id) => cleanUrl(id)), - ) + await this.buildInner() console.timeEnd(`[rolldown:${this.name}:rebuild]`) - const chunk = result.output.find( + const chunk = this.result.output.find( (v) => v.type === 'chunk' && v.name === 'hmr-update', ) if (chunk) {