diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 45da66f31ee956..0db8bf3e927749 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -3046,58 +3046,56 @@ export default async function build( staticPages ) - if (config.output === 'standalone') { - for (const file of [ - ...requiredServerFiles.files, - path.join(config.distDir, SERVER_FILES_MANIFEST), - ...loadedEnvFiles.reduce((acc, envFile) => { - if (['.env', '.env.production'].includes(envFile.path)) { - acc.push(envFile.path) - } - return acc - }, []), - ]) { - const filePath = path.join(dir, file) - const outputPath = path.join( - distDir, - 'standalone', - path.relative(outputFileTracingRoot, filePath) - ) - await fs.mkdir(path.dirname(outputPath), { - recursive: true, - }) - await fs.copyFile(filePath, outputPath) - } - await recursiveCopy( - path.join(distDir, SERVER_DIRECTORY, 'pages'), - path.join( - distDir, - 'standalone', - path.relative(outputFileTracingRoot, distDir), - SERVER_DIRECTORY, - 'pages' - ), - { overwrite: true } + for (const file of [ + ...requiredServerFiles.files, + path.join(config.distDir, SERVER_FILES_MANIFEST), + ...loadedEnvFiles.reduce((acc, envFile) => { + if (['.env', '.env.production'].includes(envFile.path)) { + acc.push(envFile.path) + } + return acc + }, []), + ]) { + const filePath = path.join(dir, file) + const outputPath = path.join( + distDir, + 'standalone', + path.relative(outputFileTracingRoot, filePath) ) - if (appDir) { - const originalServerApp = path.join( - distDir, - SERVER_DIRECTORY, - 'app' + await fs.mkdir(path.dirname(outputPath), { + recursive: true, + }) + await fs.copyFile(filePath, outputPath) + } + await recursiveCopy( + path.join(distDir, SERVER_DIRECTORY, 'pages'), + path.join( + distDir, + 'standalone', + path.relative(outputFileTracingRoot, distDir), + SERVER_DIRECTORY, + 'pages' + ), + { overwrite: true } + ) + if (appDir) { + const originalServerApp = path.join( + distDir, + SERVER_DIRECTORY, + 'app' + ) + if (existsSync(originalServerApp)) { + await recursiveCopy( + originalServerApp, + path.join( + distDir, + 'standalone', + path.relative(outputFileTracingRoot, distDir), + SERVER_DIRECTORY, + 'app' + ), + { overwrite: true } ) - if (existsSync(originalServerApp)) { - await recursiveCopy( - originalServerApp, - path.join( - distDir, - 'standalone', - path.relative(outputFileTracingRoot, distDir), - SERVER_DIRECTORY, - 'app' - ), - { overwrite: true } - ) - } } } })