- next.config.ts builds standalone output with image optimization off, and scripts/bundle-standalone.mjs puts the static files beside the server, then drops what tracing swept in but the app never runs (the MediaMTX binary and sharp's platform binaries, 79 MB). The build is 27 MB and npm pack is 4.9 MB. - The CLI gained start, which runs that server from any directory with the remembered data folder and stored key in its environment, and admin, so the messages in the UI can name a command that exists. - Messages that said "npm run …" now say "onvif-dashboard …". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { realpathSync } from "node:fs";
|
|
import path from "node:path";
|
|
import type { NextConfig } from "next";
|
|
|
|
/**
|
|
* While onvif is linked to a local checkout outside this project (e.g. the fork, installed
|
|
* with `npm install ../onvif --no-save`), Turbopack only resolves files inside its root, so
|
|
* the root must contain both (Next docs, 03-api-reference/08-turbopack.md "Root directory").
|
|
* Returns undefined for a normal install, leaving the auto-detected root alone.
|
|
*/
|
|
function linkedPackagesRoot(project: string, packages: string[]): string | undefined {
|
|
let root = project;
|
|
for (const name of packages) {
|
|
let target: string;
|
|
try {
|
|
target = realpathSync(path.join(project, "node_modules", name));
|
|
} catch {
|
|
continue;
|
|
}
|
|
while (path.relative(root, target).startsWith("..")) root = path.dirname(root);
|
|
}
|
|
return root === project ? undefined : root;
|
|
}
|
|
|
|
const project = process.cwd();
|
|
const turbopackRoot = linkedPackagesRoot(project, ["onvif"]);
|
|
|
|
const nextConfig: NextConfig = {
|
|
// What gets published: a minimal server plus only the files it needs, so installing the
|
|
// package doesn't drag in Next and React (vrek iss-ej4ahga).
|
|
output: "standalone",
|
|
// Runtime data and the downloaded MediaMTX binary are not part of the app.
|
|
outputFileTracingExcludes: { "/*": ["bin/**/*", ".data/**/*", "node_modules/@img/**/*", "node_modules/sharp/**/*"] },
|
|
// next/image is unused, and leaving it on pulls sharp's platform binaries (tens of MB).
|
|
images: { unoptimized: true },
|
|
// onvif uses Node's dgram/os modules; load it with native require instead of bundling.
|
|
serverExternalPackages: ["onvif"],
|
|
...(turbopackRoot && { turbopack: { root: turbopackRoot } }),
|
|
};
|
|
|
|
export default nextConfig;
|