Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions lib/services/bundler/bundler-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 `<platform>/.../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(
Expand Down Expand Up @@ -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,
Expand Down