esbuild for prod

This commit is contained in:
Caileb 2025-05-29 15:48:20 -05:00
parent 7e7f6e3b99
commit 1cb1c1a333
4 changed files with 27 additions and 9 deletions

View file

@ -4,9 +4,10 @@ FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy package files and install dependencies
COPY package.json package-lock.json ./
RUN npm ci --only=production
# Copy package files, config script, and install dependencies
COPY package.json package-lock.json esbuild.config.js ./
# Install all dependencies, build with esbuild, then remove devDeps
RUN npm ci && npm run build && npm prune --production
# Copy application source
COPY . .
@ -14,5 +15,8 @@ COPY . .
# Expose the application port
EXPOSE 3000
# Set NODE_ENV to production
ENV NODE_ENV=production
# Run the application
CMD ["npm", "start"]
CMD ["npm", "run", "daemon"]

12
esbuild.config.js Normal file
View file

@ -0,0 +1,12 @@
import { build } from 'esbuild';
build({
entryPoints: ['index.js'],
bundle: true,
platform: 'node',
target: 'node18',
outfile: 'dist/index.js',
minify: true,
legalComments: 'none',
drop: ['console', 'debugger'],
}).catch(() => process.exit(1));

View file

@ -5,14 +5,16 @@
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"daemon": "pm2 start index.js --name checkpoint",
"daemon": "pm2 start dist/index.js --name checkpoint",
"stop": "pm2 stop checkpoint",
"restart": "pm2 restart checkpoint",
"logs": "pm2 logs checkpoint"
"logs": "pm2 logs checkpoint",
"build": "node esbuild.config.js"
},
"devDependencies": {
"nodemon": "^3.0.2",
"prettier": "^2.8.8"
"prettier": "^2.8.8",
"esbuild": "^0.18.17"
},
"dependencies": {
"@iarna/toml": "^2.2.5",