From 03eaa951f79cfd30ff87ed34ff3ef6362e69f7ea Mon Sep 17 00:00:00 2001 From: Altair-sh Date: Tue, 29 Sep 2026 18:56:04 +0200 Subject: [PATCH] implemented release build --- README.md | 19 +++++++++++++++++++ next.config.ts | 22 ++++++++++++++++++++++ package.json | 1 + scripts/prepare-build.mjs | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 scripts/prepare-build.mjs diff --git a/README.md b/README.md index 6eb99c1..2f190e5 100644 --- a/README.md +++ b/README.md @@ -1 +1,20 @@ # paradox-save-parser-frontend + +## Install dependencies + +```sh +npm i +``` + +## Build release + +```sh +npm run build +``` + +## Run release + +```sh +cd .next/standalone +node --enable-source-maps ./server.js +``` diff --git a/next.config.ts b/next.config.ts index 59788c7..96bd9f3 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,7 +2,29 @@ import type { NextConfig } from 'next' const nextConfig: NextConfig = { experimental: { + // call tsc6 instead of import 'typescript' useTypeScriptCli: true, + // faster "npm run dev" + turbopackFileSystemCacheForDev: true, + // don't create temporary files in .next/ during "npm run build" + turbopackFileSystemCacheForBuild: false, + // options to make standalone build more debuggable + serverSourceMaps: true, + serverMinification: false, + }, + // produce .next/standalone + // which can be started by `node server.js` without any dependencies + output: 'standalone', + images: { + unoptimized: true, + }, + // remove next/image from build, which this project doesn't use + outputFileTracingExcludes: { + '*': ['node_modules/sharp/**', 'node_modules/@img/**'], + }, + // sometimes production builds ran without proper type checking + typescript: { + ignoreBuildErrors: false, }, } diff --git a/package.json b/package.json index 96ce5ad..ffa38c4 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dev": "cross-env NEXT_TELEMETRY_DISABLED=1 next dev --turbopack", "prebuild": "node scripts/replace-tsc6-with-tsc7.mjs", "build": "cross-env NEXT_TELEMETRY_DISABLED=1 next build", + "postbuild": "node scripts/prepare-build.mjs", "start": "next start", "lint": "eslint", "format": "npx prettier --write ." diff --git a/scripts/prepare-build.mjs b/scripts/prepare-build.mjs new file mode 100644 index 0000000..8d047ec --- /dev/null +++ b/scripts/prepare-build.mjs @@ -0,0 +1,36 @@ +/** +Assembles a self-contained deployment folder at ./build/ from the +`output: 'standalone'` next build output. Next.js does not include +.next/static or public/ in .next/standalone by itself, so this script +copies them in. The result can be deployed as-is and started with +`node server.js` from inside ./build/, without running `npm install`. + */ + +import { cpSync, existsSync, rmSync } from 'node:fs' +import path from 'node:path' + +const root = path.resolve(import.meta.dirname, '..') +const standaloneDir = path.join(root, '.next', 'standalone') +const buildDir = path.join(root, 'build') + +if (!existsSync(standaloneDir)) { + console.error( + `${standaloneDir} not found. Run "next build" with output: 'standalone' set in next.config.ts first.` + ) + process.exit(1) +} + +rmSync(buildDir, { recursive: true, force: true }) +cpSync(standaloneDir, buildDir, { recursive: true }) +cpSync( + path.join(root, '.next', 'static'), + path.join(buildDir, '.next', 'static'), + { recursive: true } +) + +const publicDir = path.join(root, 'public') +if (existsSync(publicDir)) { + cpSync(publicDir, path.join(buildDir, 'public'), { recursive: true }) +} + +console.log(`build assembled at ${buildDir}`)