-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBundle.js
50 lines (45 loc) · 1.22 KB
/
Bundle.js
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
49
50
import {execSync} from "child_process";
import {build} from "esbuild";
import { readFileSync, writeFileSync } from "fs";
const outDir = "dist";
function copyPackagesJson(){
const fileName = "package.json"
const fileContent = readFileSync(`./${fileName}`, "utf8");
const packageJson = JSON.parse(fileContent);
packageJson.type = "commenjs";
packageJson.exports = {
".": {
"types": "./index.d.ts",
"default": "./index.js"
}
}
writeFileSync(`./${outDir}/${fileName}`, JSON.stringify(packageJson));
}
try {
await build({
entryPoints: ["./lib/index.ts"],
bundle: true,
outfile: `./${outDir}/index.js`,
platform: "node",
target: "es6",
sourcemap: true,
loader: {".ts": "ts", ".tsx": "tsx"},
packages: "external",
format: "cjs",
plugins: [
{
name: "TypeScriptDeclarationsPlugin",
setup(build) {
build.onEnd((result) => {
if (result.errors.length === 0) {
execSync("npx tsc -p tsconfig-bundle.json");
copyPackagesJson();
}
});
}
}
]
});
} catch (e) {
console.log(`bundle failed due to ${JSON.stringify(e)}`);
}