From 5e48207198e7d29e9b02607f794331143ad2b276 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Huy Date: Sat, 7 Mar 2026 17:47:50 +0700 Subject: [PATCH] add standalone code --- .gitignore | 3 ++- next.config.ts | 1 + standalone-build.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 standalone-build.sh diff --git a/.gitignore b/.gitignore index 0dc5d70..4791e67 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,5 @@ next-env.d.ts #vs code /.vscode -package-lock.json \ No newline at end of file +package-lock.json +standalone-deploy.tar.gz \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index e9ffa30..ed23578 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,6 +2,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ + output: "standalone", }; export default nextConfig; diff --git a/standalone-build.sh b/standalone-build.sh new file mode 100755 index 0000000..c422041 --- /dev/null +++ b/standalone-build.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +echo "=== Next.js Standalone Build ===" + +APP_DIR=$(pwd) +BUILD_DIR=".next" +STANDALONE_DIR=".next/standalone" + +echo "1. Installing dependencies..." +npm install + +echo "2. Building Next.js..." +npm run build + +echo "3. Preparing standalone structure..." + +# ensure directories exist +mkdir -p $STANDALONE_DIR/.next + +# copy static assets +echo "Copying static assets..." +cp -r $BUILD_DIR/static $STANDALONE_DIR/.next/ 2>/dev/null || true + +# copy public folder +if [ -d "public" ]; then + echo "Copying public folder..." + cp -r public $STANDALONE_DIR/ +fi + +echo "4. Creating deploy package..." + +tar -czf standalone-deploy.tar.gz \ + -C $STANDALONE_DIR . \ + -C $APP_DIR public 2>/dev/null || true + +echo "" +echo "Build completed." +echo "Deploy file: standalone-deploy.tar.gz" +echo "" +echo "Run on server:" +echo "PORT=3005 node server.js"