k-l-lambda commited on
Commit
00765bc
·
1 Parent(s): 231c65e

Fix Docker build: use esbuild for backend bundling, ESM format

Browse files
Dockerfile CHANGED
@@ -16,7 +16,7 @@ WORKDIR /app
16
  COPY trigo-web/ ./
17
 
18
  # Install build tools globally
19
- RUN npm install -g tsx jison typescript
20
 
21
  # Install dependencies
22
  # Root: production only (skip onnxruntime-node which requires native compilation)
@@ -32,8 +32,8 @@ RUN tsx tools/buildJisonParser.ts
32
  # Build frontend (generates dist folder)
33
  RUN cd app && npm run build
34
 
35
- # Build backend TypeScript - use global tsc directly
36
- RUN cd backend && tsc
37
 
38
  # Set environment variables for Hugging Face Spaces
39
  ENV PORT=7860
 
16
  COPY trigo-web/ ./
17
 
18
  # Install build tools globally
19
+ RUN npm install -g tsx jison typescript esbuild
20
 
21
  # Install dependencies
22
  # Root: production only (skip onnxruntime-node which requires native compilation)
 
32
  # Build frontend (generates dist folder)
33
  RUN cd app && npm run build
34
 
35
+ # Build backend with esbuild (handles ESM imports without .js extensions)
36
+ RUN esbuild backend/src/server.ts --bundle --platform=node --target=node20 --format=esm --outfile=backend/dist/server.js --external:express --external:socket.io --external:cors --external:dotenv --external:uuid
37
 
38
  # Set environment variables for Hugging Face Spaces
39
  ENV PORT=7860
trigo-web/backend/package.json CHANGED
@@ -3,11 +3,11 @@
3
  "version": "1.0.0",
4
  "type": "module",
5
  "description": "Backend server for Trigo game",
6
- "main": "dist/backend/src/server.js",
7
  "scripts": {
8
  "dev": "nodemon --watch src --exec tsx src/server.ts",
9
  "build": "tsc",
10
- "start": "node dist/backend/src/server.js",
11
  "test": "echo \"Error: no test specified\" && exit 1"
12
  },
13
  "keywords": [
 
3
  "version": "1.0.0",
4
  "type": "module",
5
  "description": "Backend server for Trigo game",
6
+ "main": "dist/server.js",
7
  "scripts": {
8
  "dev": "nodemon --watch src --exec tsx src/server.ts",
9
  "build": "tsc",
10
+ "start": "node dist/server.js",
11
  "test": "echo \"Error: no test specified\" && exit 1"
12
  },
13
  "keywords": [
trigo-web/backend/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "compilerOptions": {
3
  "target": "ES2020",
4
- "module": "ESNext",
5
  "lib": ["ES2020"],
6
  "outDir": "./dist",
7
  "rootDir": "../",
@@ -9,7 +9,7 @@
9
  "esModuleInterop": true,
10
  "skipLibCheck": true,
11
  "forceConsistentCasingInFileNames": true,
12
- "moduleResolution": "bundler",
13
  "resolveJsonModule": true,
14
  "declaration": true,
15
  "declarationMap": true,
@@ -18,12 +18,12 @@
18
  "allowJs": true,
19
  "noImplicitAny": false
20
  },
21
- "include": ["src/**/*", "../inc/**/*"],
22
- "exclude": ["node_modules", "dist", "../inc/trigo/parserInit.ts", "../inc/tgn/tgn.jison.cjs", "../inc/config.ts"],
23
  "ts-node": {
24
  "esm": true,
25
  "compilerOptions": {
26
- "module": "ESNext"
27
  }
28
  }
29
  }
 
1
  {
2
  "compilerOptions": {
3
  "target": "ES2020",
4
+ "module": "Node20",
5
  "lib": ["ES2020"],
6
  "outDir": "./dist",
7
  "rootDir": "../",
 
9
  "esModuleInterop": true,
10
  "skipLibCheck": true,
11
  "forceConsistentCasingInFileNames": true,
12
+ "moduleResolution": "Node20",
13
  "resolveJsonModule": true,
14
  "declaration": true,
15
  "declarationMap": true,
 
18
  "allowJs": true,
19
  "noImplicitAny": false
20
  },
21
+ "include": ["src/**/*", "../inc/trigo/**/*"],
22
+ "exclude": ["node_modules", "dist", "../inc/trigo/parserInit.ts"],
23
  "ts-node": {
24
  "esm": true,
25
  "compilerOptions": {
26
+ "module": "Node20"
27
  }
28
  }
29
  }