Created
April 22, 2026 22:19
-
-
Save meyt/8135833fe511a27bd28d070ccef3bd0a to your computer and use it in GitHub Desktop.
Build express.js app with all dependencies (wasm and native binary excluded) into single file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import path from 'path' | |
| import { fileURLToPath } from 'url'; | |
| import * as esbuild from "esbuild"; | |
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | |
| try { | |
| await esbuild.build({ | |
| entryPoints: [path.resolve(__dirname, './server.mjs')], | |
| bundle: true, | |
| sourcemap: false, | |
| minify: false, | |
| platform: "node", | |
| target: ["node18.6"], | |
| packages: "bundle", | |
| define: { | |
| "process.env.NODE_ENV": "'production'", | |
| }, | |
| outfile: path.resolve(__dirname, '../dist/server.cjs') | |
| }); | |
| console.log("Server bundled successfully for production! 🚀"); | |
| } catch (e) { | |
| console.error("An error occurred during bundling:", e); | |
| process.exit(1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "express-app", | |
| "version": "1.0.0", | |
| "type": "module", | |
| "scripts": { | |
| "build:server": "node esbuild.mjs", | |
| }, | |
| "dependencies": { | |
| "express": "^4.19.2" | |
| }, | |
| "devDependencies": { | |
| "esbuild": "^0.28.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment