Files
2026-06-07 03:58:32 -04:00

23 lines
889 B
JavaScript

// After `next build` with output:"standalone", Next does NOT copy static assets or
// /public into the standalone folder. PM2 runs .next/standalone/server.js, so copy
// them in here. Safe to run anywhere — no-ops if there's no standalone output.
import { cp } from "node:fs/promises";
import { existsSync } from "node:fs";
import path from "node:path";
const root = process.cwd();
const standalone = path.join(root, ".next", "standalone");
if (!existsSync(standalone)) {
console.log("postbuild: no standalone output, skipping");
process.exit(0);
}
await cp(path.join(root, ".next", "static"), path.join(standalone, ".next", "static"), {
recursive: true,
});
if (existsSync(path.join(root, "public"))) {
await cp(path.join(root, "public"), path.join(standalone, "public"), { recursive: true });
}
console.log("postbuild: ✓ copied static (+ public) into .next/standalone");