diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 159bb43c..8d19cee3 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -143,40 +143,41 @@ export async function bundle( configFile: config.vite?.configFile }) - let clientResult!: Rollup.RollupOutput | null - let serverResult!: Rollup.RollupOutput - - await task('building client + server bundles', async () => { - clientResult = config.mpa - ? null - : ((await build(await resolveViteConfig(false))) as Rollup.RollupOutput) - serverResult = (await build( - await resolveViteConfig(true) - )) as Rollup.RollupOutput - }) + const serverResult = await task( + 'building server bundle', + () => resolveViteConfig(true).then(build) as Promise + ) - if (config.mpa) { - // in MPA mode, we need to copy over the non-js asset files from the - // server build since there is no client-side build. - await Promise.all( - serverResult.output.map(async (chunk) => { - if (!chunk.fileName.endsWith('.js')) { - const tempPath = path.resolve(config.tempDir, chunk.fileName) - const outPath = path.resolve(config.outDir, chunk.fileName) - await fs.copy(tempPath, outPath) + const clientResult = !config.mpa + ? await task( + 'building client bundle', + () => + resolveViteConfig(false).then(build) as Promise + ) + : await task('building client bundle (MPA)', async () => { + // in MPA mode, we need to copy over the non-js asset files from the + // server build since there is no client-side build. + await Promise.all( + serverResult.output.map(async (chunk) => { + if (!chunk.fileName.endsWith('.js')) { + const tempPath = path.resolve(config.tempDir, chunk.fileName) + const outPath = path.resolve(config.outDir, chunk.fileName) + await fs.copy(tempPath, outPath) + } + }) + ) + // also copy over public dir + const publicDir = path.resolve(config.srcDir, 'public') + if (fs.existsSync(publicDir)) { + await fs.copy(publicDir, config.outDir) + } + // build