build size reduse it
This commit is contained in:
49
scripts/bundle.sh
Executable file
49
scripts/bundle.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Produce the deployable artifact for a non-Docker deploy.
|
||||
#
|
||||
# Copying .next/ wholesale is what filled the production disk: a working tree's
|
||||
# .next/ reaches 2+ GB, but only three paths are read at runtime —
|
||||
# .next/standalone the server + its traced node_modules
|
||||
# .next/static hashed client assets (served by nginx at /_next/static/)
|
||||
# public unhashed public assets
|
||||
# Everything else (.next/cache, .next/dev, .next/server, .next/types) is
|
||||
# build-host state and must never be shipped.
|
||||
#
|
||||
# Usage: npm run bundle -> dist/loyaly-mer-login.tar.gz
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
OUT="dist"
|
||||
STAGE="$OUT/bundle"
|
||||
|
||||
for p in .next/standalone .next/static public; do
|
||||
if [ ! -d "$p" ]; then
|
||||
echo "error: $p missing — run 'npm run build' first" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
rm -rf "$STAGE"
|
||||
mkdir -p "$STAGE"
|
||||
|
||||
# standalone already contains server.js, package.json and traced node_modules,
|
||||
# and expects static/ and public/ to sit beside it in the same layout.
|
||||
cp -R .next/standalone/. "$STAGE/"
|
||||
mkdir -p "$STAGE/.next"
|
||||
cp -R .next/static "$STAGE/.next/static"
|
||||
cp -R public "$STAGE/public"
|
||||
|
||||
TARBALL="$OUT/loyaly-mer-login.tar.gz"
|
||||
rm -f "$TARBALL"
|
||||
tar -czf "$TARBALL" -C "$STAGE" .
|
||||
|
||||
echo
|
||||
echo "bundle: $(du -sh "$STAGE" | cut -f1) ($STAGE)"
|
||||
echo "tarball: $(du -sh "$TARBALL" | cut -f1) ($TARBALL)"
|
||||
echo
|
||||
echo "deploy: scp $TARBALL <host>:/srv/ && tar -xzf loyaly-mer-login.tar.gz -C /srv/app"
|
||||
echo "run: PORT=3000 HOSTNAME=0.0.0.0 NODE_ENV=production node server.js"
|
||||
Reference in New Issue
Block a user