-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
22 lines (20 loc) · 730 Bytes
/
Copy pathbuild.js
File metadata and controls
22 lines (20 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import path from "path";
import fs from "fs";
// NodeJS Build
const NODE_FIX =
'#!/usr/bin/env node\n\nimport { createRequire as createImportMetaRequire } from "module"; import.meta.require ||= (id) => createImportMetaRequire(import.meta.url)(id);\n';
const BUILD_DIR = "build";
const nodeBuild = await Bun.build({
entrypoints: ["./index.ts"],
target: "node",
minify: true,
naming: "[dir]/[name].[ext]",
});
// Write output files
for (const result of nodeBuild.outputs) {
const fileContent = NODE_FIX + (await result.text());
const destDir = path.join(import.meta.dir, BUILD_DIR);
const dest = path.join(destDir, result.path);
fs.existsSync(destDir) || fs.mkdirSync(destDir);
Bun.write(dest, fileContent);
}