@@ -129,12 +129,9 @@ export class BundlerCompilerService
129129
130130 console . log ( `🔥 Copying from ${ distOutput } to ${ destDir } ` ) ;
131131
132- // For HMR updates, only copy changed files; for full builds, copy everything
133- if (
134- message . isHMR &&
135- message . changedFiles &&
136- message . changedFiles . length > 0
137- ) {
132+ // Determine which files to copy based on build type and changes
133+ if ( message . isHMR ) {
134+ // HMR updates: only copy changed files
138135 console . log (
139136 "🔥 HMR update - copying only changed files for:" ,
140137 message . changedFiles ,
@@ -161,6 +158,24 @@ export class BundlerCompilerService
161158 ) ;
162159 }
163160
161+ this . copyViteBundleToNative ( distOutput , destDir , filesToCopy ) ;
162+ } else if (
163+ message . buildType === "incremental" &&
164+ message . changedFiles &&
165+ message . changedFiles . length > 0
166+ ) {
167+ // Incremental builds: only copy files that are likely affected by the changes
168+ console . log (
169+ "🔥 Incremental build - copying only relevant files for:" ,
170+ message . changedFiles ,
171+ ) ;
172+
173+ const filesToCopy = this . getIncrementalFilesToCopy (
174+ message . emittedFiles ,
175+ message . changedFiles ,
176+ ) ;
177+ console . log ( "🔥 Incremental build - files to copy:" , filesToCopy ) ;
178+
164179 this . copyViteBundleToNative ( distOutput , destDir , filesToCopy ) ;
165180 } else {
166181 console . log ( "🔥 Full build - copying all files" ) ;
@@ -872,8 +887,11 @@ export class BundlerCompilerService
872887
873888 try {
874889 if ( specificFiles ) {
875- // HMR mode: only copy specific files
876- console . log ( "🔥 HMR: Copying specific files:" , specificFiles ) ;
890+ // Selective mode: only copy specific files (HMR or incremental)
891+ console . log (
892+ "🔥 Selective copy - copying specific files:" ,
893+ specificFiles ,
894+ ) ;
877895
878896 // Ensure destination directory exists
879897 fs . mkdirSync ( destDir , { recursive : true } ) ;
@@ -890,7 +908,7 @@ export class BundlerCompilerService
890908
891909 fs . copyFileSync ( srcPath , destPath ) ;
892910
893- console . log ( `🔥 HMR: Copied ${ file } ` ) ;
911+ console . log ( `🔥 Copied ${ file } ` ) ;
894912 }
895913 } else {
896914 // Full build mode: clean and copy everything
@@ -916,6 +934,58 @@ export class BundlerCompilerService
916934 }
917935 }
918936
937+ private getIncrementalFilesToCopy (
938+ emittedFiles : string [ ] ,
939+ changedFiles : string [ ] ,
940+ ) : string [ ] {
941+ // For incremental builds, we need to determine which emitted files are likely affected
942+ // by the source file changes
943+
944+ const filesToCopy : string [ ] = [ ] ;
945+
946+ // Always copy bundle files as they contain the compiled source code
947+ // ignoring vendor files as they are less likely to change frequently
948+ const bundleFiles = emittedFiles . filter (
949+ ( file ) =>
950+ ! file . includes ( "vendor" ) &&
951+ ( file . includes ( "bundle" ) ||
952+ file . includes ( "main" ) ||
953+ file . includes ( "app" ) ||
954+ file . endsWith ( ".mjs" ) ||
955+ file . endsWith ( ".js" ) ) ,
956+ ) ;
957+ filesToCopy . push ( ...bundleFiles ) ;
958+
959+ // Always copy source maps for debugging
960+ const sourceMapFiles = emittedFiles . filter (
961+ ( file ) => ! file . includes ( "vendor" ) && file . endsWith ( ".map" ) ,
962+ ) ;
963+ filesToCopy . push ( ...sourceMapFiles ) ;
964+
965+ // Only handle assets if they're explicitly referenced in the changed files
966+ const hasAssetChanges = changedFiles . some (
967+ ( file ) =>
968+ file . includes ( "/assets/" ) ||
969+ file . includes ( "/static/" ) ||
970+ file . includes ( "/public/" ) ,
971+ ) ;
972+
973+ if ( hasAssetChanges ) {
974+ // Only copy assets if there are explicit asset-related changes
975+ const assetFiles = emittedFiles . filter (
976+ ( file ) =>
977+ file . includes ( "assets/" ) ||
978+ file . includes ( "static/" ) ||
979+ file . includes ( "fonts/" ) ||
980+ file . includes ( "images/" ) ,
981+ ) ;
982+ filesToCopy . push ( ...assetFiles ) ;
983+ }
984+
985+ // Remove duplicates and return
986+ return [ ...new Set ( filesToCopy ) ] ;
987+ }
988+
919989 private notifyHMRClients ( message : any ) {
920990 // Send WebSocket notification to HMR clients
921991 try {
0 commit comments