diff --git a/lib/services/bundler/bundler-compiler-service.ts b/lib/services/bundler/bundler-compiler-service.ts index 3eb880b2ba..d870bdc43f 100644 --- a/lib/services/bundler/bundler-compiler-service.ts +++ b/lib/services/bundler/bundler-compiler-service.ts @@ -126,13 +126,9 @@ export class BundlerCompilerService } // Copy Vite output files directly to platform destination - const distOutput = path.join( - projectData.projectDir, - ".ns-vite-build", - ); - const destDir = path.join( - platformData.appDestinationDirectoryPath, - this.$options.hostProjectModuleName, + const { distOutput, destDir } = this.getVitePaths( + platformData, + projectData, ); if (debugLog) { @@ -380,6 +376,21 @@ export class BundlerCompilerService delete this.bundlerProcesses[platformData.platformNameLowerCase]; const exitCode = typeof arg === "number" ? arg : arg && arg.code; if (exitCode === 0) { + // In watch mode the Vite output is copied into the native + // project from the `emittedFiles` IPC message. A non-watch + // build (`ns build`, `ns run --justlaunch`) has no IPC + // channel — `startBundleProcess` sets `stdio: "inherit"` + // when `prepareData.watch` is false — so that copy never + // runs and `/.../assets/app` stays empty, leaving + // the Static Binding Generator with no input. Copy the full + // Vite bundle here instead. + if (this.getBundler() === "vite") { + const { distOutput, destDir } = this.getVitePaths( + platformData, + projectData, + ); + this.copyViteBundleToNative(distOutput, destDir); + } resolve(); } else { const error: any = new Error( @@ -845,6 +856,21 @@ export class BundlerCompilerService return this.$projectConfigService.getValue(`bundler`, "webpack"); } + // The Vite output directory and its destination in the native project — + // shared by the watch-mode `emittedFiles` copy and the non-watch copy. + private getVitePaths( + platformData: IPlatformData, + projectData: IProjectData, + ): { distOutput: string; destDir: string } { + return { + distOutput: path.join(projectData.projectDir, ".ns-vite-build"), + destDir: path.join( + platformData.appDestinationDirectoryPath, + this.$options.hostProjectModuleName, + ), + }; + } + private copyViteBundleToNative( distOutput: string, destDir: string,