|
1 | 1 | import esbuild from "esbuild"; |
2 | 2 | import { resolve } from "path"; |
3 | 3 |
|
| 4 | + |
| 5 | +const commonParams = { |
| 6 | + bundle: true, |
| 7 | + format: "esm", |
| 8 | + minify: true, |
| 9 | + outExtension: { ".js": ".mjs" }, |
| 10 | + loader: { |
| 11 | + ".png": "file", |
| 12 | + ".pkpass": "file", |
| 13 | + ".json": "file", |
| 14 | + }, // File loaders |
| 15 | + target: "es2022", // Target ES2022 |
| 16 | + sourcemap: false, |
| 17 | + platform: "node", |
| 18 | + external: ["aws-sdk", "moment-timezone", "passkit-generator", "fastify"], |
| 19 | + alias: { |
| 20 | + 'moment-timezone': resolve(process.cwd(), '../../node_modules/moment-timezone/builds/moment-timezone-with-data-10-year-range.js') |
| 21 | + }, |
| 22 | + banner: { |
| 23 | + js: ` |
| 24 | + import path from 'path'; |
| 25 | + import { fileURLToPath } from 'url'; |
| 26 | + import { createRequire as topLevelCreateRequire } from 'module'; |
| 27 | + const require = topLevelCreateRequire(import.meta.url); |
| 28 | + const __filename = fileURLToPath(import.meta.url); |
| 29 | + const __dirname = path.dirname(__filename); |
| 30 | + `.trim(), |
| 31 | + }, // Banner for compatibility with CommonJS |
| 32 | +} |
4 | 33 | esbuild |
5 | 34 | .build({ |
6 | | - entryPoints: ["api/lambda.js"], // Entry file |
7 | | - bundle: true, |
8 | | - format: "esm", |
9 | | - minify: true, |
| 35 | + ...commonParams, |
| 36 | + entryPoints: ["api/index.js"], |
10 | 37 | outdir: "../../dist/lambda/", |
11 | | - outExtension: { ".js": ".mjs" }, |
12 | | - loader: { |
13 | | - ".png": "file", |
14 | | - ".pkpass": "file", |
15 | | - ".json": "file", |
16 | | - }, // File loaders |
17 | | - target: "es2022", // Target ES2022 |
18 | | - sourcemap: false, |
19 | | - platform: "node", |
20 | | - external: ["aws-sdk", "moment-timezone", "passkit-generator", "fastify"], |
21 | | - alias: { |
22 | | - 'moment-timezone': resolve(process.cwd(), '../../node_modules/moment-timezone/builds/moment-timezone-with-data-10-year-range.js') |
23 | | - }, |
24 | | - banner: { |
25 | | - js: ` |
26 | | - import path from 'path'; |
27 | | - import { fileURLToPath } from 'url'; |
28 | | - import { createRequire as topLevelCreateRequire } from 'module'; |
29 | | - const require = topLevelCreateRequire(import.meta.url); |
30 | | - const __filename = fileURLToPath(import.meta.url); |
31 | | - const __dirname = path.dirname(__filename); |
32 | | - `.trim(), |
33 | | - }, // Banner for compatibility with CommonJS |
34 | 38 | }) |
35 | | - .then(() => console.log("Build completed successfully!")) |
| 39 | + .then(() => console.log("API server build completed successfully!")) |
| 40 | + .catch((error) => { |
| 41 | + console.error("API server build failed:", error); |
| 42 | + process.exit(1); |
| 43 | + }); |
| 44 | + |
| 45 | + esbuild |
| 46 | + .build({ |
| 47 | + ...commonParams, |
| 48 | + entryPoints: ["api/sqs/index.js"], |
| 49 | + outdir: "../../dist/sqsConsumer/", |
| 50 | + }) |
| 51 | + .then(() => console.log("SQS consumer build completed successfully!")) |
36 | 52 | .catch((error) => { |
37 | | - console.error("Build failed:", error); |
| 53 | + console.error("SQS consumer build failed:", error); |
38 | 54 | process.exit(1); |
39 | 55 | }); |
0 commit comments