-
Notifications
You must be signed in to change notification settings - Fork 18
/
esbuild-script.mjs
41 lines (36 loc) · 1.29 KB
/
esbuild-script.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* global console */
/* global process */
/* eslint no-console: "off" */
/*eslint no-process-exit: "off"*/
import botLayer from '@medplum/bot-layer/package.json' with { type: 'json' };
import esbuild from 'esbuild';
import fastGlob from 'fast-glob';
// Find all TypeScript files in your source directory
const entryPoints = fastGlob.sync('./src/**/*.ts').filter((file) => !file.endsWith('test.ts'));
const botLayerDeps = Object.keys(botLayer.dependencies);
// Define the esbuild options
const esbuildOptions = {
entryPoints: entryPoints,
bundle: true, // Bundle imported functions
outdir: './dist', // Output directory for compiled files
platform: 'node', // or 'node', depending on your target platform
loader: {
'.ts': 'ts', // Load TypeScript files
},
resolveExtensions: ['.ts'],
external: botLayerDeps,
format: 'cjs', // Set output format as ECMAScript modules
target: 'es2020', // Set the target ECMAScript version
tsconfig: 'tsconfig.json',
footer: { js: 'Object.assign(exports, module.exports);' }, // Required for VM Context Bots
};
// Build using esbuild
esbuild
.build(esbuildOptions)
.then(() => {
console.log('Build completed successfully!');
})
.catch((error) => {
console.error('Build failed:', JSON.stringify(error, null, 2));
process.exit(1);
});