32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import { cpSync, existsSync, rmSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const appRoot = path.resolve(__dirname, "..");
|
|
|
|
const standaloneRoot = path.join(appRoot, ".next", "standalone");
|
|
const nextStaticSource = path.join(appRoot, ".next", "static");
|
|
const nextStaticTarget = path.join(standaloneRoot, ".next", "static");
|
|
const publicSource = path.join(appRoot, "public");
|
|
const publicTarget = path.join(standaloneRoot, "public");
|
|
|
|
function copyDirectory(source, target, label) {
|
|
if (!existsSync(source)) {
|
|
console.log(`[standalone-assets] Skipping ${label}; source not found.`);
|
|
return;
|
|
}
|
|
|
|
rmSync(target, { recursive: true, force: true });
|
|
cpSync(source, target, { recursive: true });
|
|
console.log(`[standalone-assets] Copied ${label}.`);
|
|
}
|
|
|
|
if (!existsSync(standaloneRoot)) {
|
|
throw new Error("Next standalone output was not found at .next/standalone.");
|
|
}
|
|
|
|
copyDirectory(nextStaticSource, nextStaticTarget, ".next/static");
|
|
copyDirectory(publicSource, publicTarget, "public");
|