@@ -9,7 +9,10 @@ import {
99} from 'rolldown/experimental'
1010import { ChunkMetadataMap , resolveRolldownOptions } from '../build'
1111import { BUNDLED_DEV_CLIENT_FILENAME } from '../constants'
12- import { getHmrImplementation } from '../plugins/clientInjections'
12+ import {
13+ getHmrImplementation ,
14+ getRolldownDevRuntimeFiles ,
15+ } from '../plugins/clientInjections'
1316import { createDebugger , formatAndTruncateFileList } from '../utils'
1417import { convertToDevWatchOptions } from '../watch'
1518import type { DevEnvironment } from './environment'
@@ -60,7 +63,8 @@ export class MemoryFiles {
6063
6164export class BundledDev {
6265 private _devEngine ! : DevEngine
63- private viteRuntime ?: string
66+ /** the vite client and the rolldown runtime; set before the first build so `hasBuildOutput` can count them */
67+ private staticFiles = new Map < string , MemoryFile > ( )
6468 private initialBuildCompleted = false
6569 private _closed = false
6670 private clients = new Clients ( )
@@ -107,17 +111,14 @@ export class BundledDev {
107111 private pendingPayloadFilenames = new Set < string > ( )
108112
109113 get hasBuildOutput ( ) : boolean {
110- return (
111- this . memoryFiles . size > 1 ||
112- ( this . memoryFiles . size === 1 &&
113- ! this . memoryFiles . has ( BUNDLED_DEV_CLIENT_FILENAME ) )
114- )
114+ return this . memoryFiles . size > this . staticFiles . size
115115 }
116116
117117 async listen ( ) : Promise < void > {
118118 this . _closed = false
119119 debug ?.( 'INITIAL: setup bundle options' )
120120 const rolldownOptions = await this . getRolldownOptions ( )
121+ await this . storeStaticFiles ( )
121122 // NOTE: only single outputOptions is supported here
122123 if (
123124 Array . isArray ( rolldownOptions . output ) &&
@@ -262,10 +263,6 @@ export class BundledDev {
262263 debug ?.( 'INITIAL: run error' , e )
263264 } ,
264265 )
265- this . viteRuntime = await getHmrImplementation (
266- this . environment . getTopLevelConfig ( ) ,
267- )
268- this . storeOutputFiles ( [ ] )
269266 this . waitForInitialBuildFinish ( ) . then ( ( ) => {
270267 if ( this . _closed ) return
271268 debug ?.( 'INITIAL: build done' )
@@ -373,14 +370,27 @@ export class BundledDev {
373370 this . initialBuildCompleted = false
374371 }
375372
373+ private async storeStaticFiles ( ) : Promise < void > {
374+ const sources = new Map < string , string > ( [
375+ [
376+ BUNDLED_DEV_CLIENT_FILENAME ,
377+ await getHmrImplementation ( this . environment . getTopLevelConfig ( ) ) ,
378+ ] ,
379+ ...getRolldownDevRuntimeFiles ( ) ,
380+ ] )
381+ this . staticFiles . clear ( )
382+ for ( const [ fileName , source ] of sources ) {
383+ const file = {
384+ source,
385+ etag : getEtag ( Buffer . from ( source ) , { weak : true } ) ,
386+ }
387+ this . staticFiles . set ( fileName , file )
388+ this . memoryFiles . set ( fileName , file )
389+ }
390+ }
391+
376392 private storeOutputFiles ( output : RolldownOutput [ 'output' ] [ number ] [ ] ) : void {
377393 // NOTE: don't clear memoryFiles here as incremental build reuses the files
378- if ( this . viteRuntime ) {
379- this . memoryFiles . set ( BUNDLED_DEV_CLIENT_FILENAME , {
380- source : this . viteRuntime ,
381- etag : getEtag ( Buffer . from ( this . viteRuntime ) , { weak : true } ) ,
382- } )
383- }
384394 for ( const outputFile of output ) {
385395 this . memoryFiles . set ( outputFile . fileName , ( ) => {
386396 const source =
0 commit comments