Skip to content

Commit c5f66b8

Browse files
committed
fix esbuild
1 parent d1a07e1 commit c5f66b8

File tree

3 files changed

+154
-23
lines changed

3 files changed

+154
-23
lines changed

backend/esbuild.config.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
const esbuild = require('esbuild');
2+
const { copy } = require('esbuild-plugin-copy');
23
const { nodeExternalsPlugin } = require('esbuild-node-externals');
34

45
const isProduction = process.env.NODE_ENV === 'production';
56

6-
(async () => {
7-
const ctx = await esbuild.context({
8-
entryPoints: ['index.ts'],
9-
bundle: true,
10-
platform: 'node',
11-
target: 'node22',
12-
outfile: 'dist/index.js',
13-
tsconfig: 'tsconfig.json',
14-
sourcemap: !isProduction,
15-
minify: isProduction,
16-
external: ['express'],
17-
plugins: [nodeExternalsPlugin()],
18-
});
19-
20-
if (!isProduction) {
21-
console.log('👀 Watching for file changes...');
22-
await ctx.watch();
23-
} else {
24-
console.log('🚀 Building for production...');
25-
await ctx.dispose();
26-
}
27-
})();
7+
esbuild.build({
8+
entryPoints: ['index.ts'],
9+
bundle: true,
10+
platform: 'node',
11+
target: 'node22',
12+
outfile: 'dist/index.js',
13+
tsconfig: 'tsconfig.json',
14+
sourcemap: !isProduction,
15+
minify: isProduction,
16+
external: ['express'],
17+
plugins: [
18+
nodeExternalsPlugin(),
19+
copy({
20+
assets: [
21+
{ from: ['./package.json'], to: ['./package.json'] },
22+
{ from: ['./src/config/config.json'], to: ['./config/config.json'] },
23+
],
24+
}),
25+
],
26+
}).then(() => {
27+
console.log('✅ Build complete.');
28+
}).catch(() => {
29+
console.error('❌ Build failed.');
30+
process.exit(1);
31+
});

backend/package-lock.json

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "PORT=5000 nodemon",
77
"start": "node ./index.js",
8-
"build": "NODE_ENV=production node esbuild.config.js && cp -r ./package.json ./src/config ./dist",
8+
"build": "NODE_ENV=production node esbuild.config.js",
99
"lint": "eslint .",
1010
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
1111
"docker:build:dev": "docker build . -t ghcr.io/anthonygress/lab-dash-backend:latest",
@@ -39,6 +39,7 @@
3939
"@types/node": "^22.13.1",
4040
"esbuild": "^0.25.0",
4141
"esbuild-node-externals": "^1.18.0",
42+
"esbuild-plugin-copy": "^2.1.1",
4243
"eslint": "^9.17.0",
4344
"eslint-plugin-import": "^2.28.1",
4445
"nodemon": "^3.1.9",

0 commit comments

Comments
 (0)