diff --git a/Dockerfile b/Dockerfile index 371938e..fe4792d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,12 @@ 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 application source +# Copy package files, config script +COPY package.json package-lock.json esbuild.config.js ./ +# Copy application source before build so esbuild can locate entry files COPY . . +# Install all dependencies, create dist folder, build with esbuild, then remove devDeps +RUN npm ci && mkdir -p dist && npm run build && npm prune --production # Expose the application port EXPOSE 3000 diff --git a/esbuild.config.js b/esbuild.config.js new file mode 100644 index 0000000..504a746 --- /dev/null +++ b/esbuild.config.js @@ -0,0 +1,15 @@ +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((e) => { + console.error('esbuild failed:', e); + process.exit(1); +}); \ No newline at end of file diff --git a/index.js b/index.js index 596c713..9b90686 100644 --- a/index.js +++ b/index.js @@ -58,11 +58,6 @@ if (process.argv.includes('-d')) { process.exit(0); } -// Disable console.log in production to suppress output in daemon mode -if (process.env.NODE_ENV === 'production') { - console.log = () => {}; -} - const pluginRegistry = []; export function registerPlugin(pluginName, handler) { pluginRegistry.push({ name: pluginName, handler }); diff --git a/package.json b/package.json index a47e276..3d40e76 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "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",