generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 9
/
esbuild.config.mjs
41 lines (37 loc) · 1.15 KB
/
esbuild.config.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
import chalk from "chalk";
import { analyzeMetafile, build } from "esbuild";
(async () => {
try {
const startTime = Date.now();
console.info(
chalk.bold(`🚀 ${chalk.blueBright("await-remote-run")} Build\n`),
);
const result = await build({
entryPoints: ["./src/main.ts"],
outfile: "dist/index.mjs",
metafile: true,
bundle: true,
format: "esm",
platform: "node",
target: ["node20"],
treeShaking: true,
// Ensure require is properly defined: https://github.com/evanw/esbuild/issues/1921
banner: {
js:
"import { createRequire } from 'module';\n" +
"const require = createRequire(import.meta.url);",
},
});
const analysis = await analyzeMetafile(result.metafile);
console.info(`📝 Bundle Analysis:${analysis}`);
console.info(
`${chalk.bold.green("✔ Bundled successfully!")} (${
Date.now() - startTime
}ms)`,
);
} catch (error) {
console.error(`🧨 ${chalk.red.bold("Failed:")} ${error.message}`);
console.debug(`📚 ${chalk.blueBright.bold("Stack:")} ${error.stack}`);
process.exit(1);
}
})();