esbuild for prod
This commit is contained in:
parent
7e7f6e3b99
commit
1cb1c1a333
4 changed files with 27 additions and 9 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -4,9 +4,10 @@ FROM node:18-alpine
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files and install dependencies
|
# Copy package files, config script, and install dependencies
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json esbuild.config.js ./
|
||||||
RUN npm ci --only=production
|
# Install all dependencies, build with esbuild, then remove devDeps
|
||||||
|
RUN npm ci && npm run build && npm prune --production
|
||||||
|
|
||||||
# Copy application source
|
# Copy application source
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
@ -14,5 +15,8 @@ COPY . .
|
||||||
# Expose the application port
|
# Expose the application port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Set NODE_ENV to production
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
CMD ["npm", "start"]
|
CMD ["npm", "run", "daemon"]
|
||||||
|
|
@ -11,4 +11,4 @@ services:
|
||||||
- /volume1/docker/Checkpoint/.env:/app/.env:ro
|
- /volume1/docker/Checkpoint/.env:/app/.env:ro
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
12
esbuild.config.js
Normal file
12
esbuild.config.js
Normal 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));
|
||||||
10
package.json
10
package.json
|
|
@ -5,14 +5,16 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"dev": "nodemon 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",
|
"stop": "pm2 stop checkpoint",
|
||||||
"restart": "pm2 restart checkpoint",
|
"restart": "pm2 restart checkpoint",
|
||||||
"logs": "pm2 logs checkpoint"
|
"logs": "pm2 logs checkpoint",
|
||||||
|
"build": "node esbuild.config.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^3.0.2",
|
"nodemon": "^3.0.2",
|
||||||
"prettier": "^2.8.8"
|
"prettier": "^2.8.8",
|
||||||
|
"esbuild": "^0.18.17"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iarna/toml": "^2.2.5",
|
"@iarna/toml": "^2.2.5",
|
||||||
|
|
@ -31,4 +33,4 @@
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue