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
12 changes: 12 additions & 0 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export default class Build extends Command {

await generate({ setup: true, basePath })

// Copy .env file to temporary directory to make NEXT_PUBLIC_* variables available during build
copyDotenv(basePath, tmpDir)

const packageManager = getPreferredPackageManager()

const buildResult = spawnSync(`${packageManager} run build`, {
Expand Down Expand Up @@ -176,3 +179,12 @@ async function checkDeps(basePath: string): Promise<Array<string>> {
return []
}
}

export function copyDotenv(basePath: string, tmpPath: string) {
const dotenvFile = `${basePath}/.env`
const destinationFile = `${tmpPath}/.env`

if (existsSync(dotenvFile)) {
copySync(dotenvFile, destinationFile)
}
}
Loading