-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.mjs
48 lines (43 loc) · 1.16 KB
/
build.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
42
43
44
45
46
47
48
// Your bundler file
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as url from 'node:url';
import * as esbuild from 'esbuild';
import { nodeExternalsPlugin } from 'esbuild-node-externals';
const buildConfigs = {
bundle: true,
platform: 'node',
target: 'node20',
format: 'esm',
sourcemap: 'linked',
plugins: [
nodeExternalsPlugin(),
{
name: 'import.meta.url',
setup({ onLoad }) {
onLoad({ filter: /.*\.ts/g, namespace: 'file' }, (args) => {
let code = fs.readFileSync(args.path, 'utf8');
code = code
.replaceAll(/\bimport\.meta\.url\b/g, JSON.stringify(url.pathToFileURL(args.path)))
.replaceAll(/\bimport\.meta\.dirname\b/g, JSON.stringify(path.dirname(args.path)));
return { contents: code, loader: 'ts' };
});
},
},
],
};
await esbuild.build({
entryPoints: ['bin/main.ts'],
outfile: 'dist/index.mjs',
...buildConfigs,
});
await esbuild.build({
entryPoints: ['bin/cron.ts'],
outfile: 'dist/cron.mjs',
...buildConfigs,
});
await esbuild.build({
entryPoints: ['bin/mq.ts'],
outfile: 'dist/mq.mjs',
...buildConfigs,
});