-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.mjs
115 lines (106 loc) · 2.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// import chokidar from "chokidar";
import esbuild from "esbuild";
import fs from "fs";
import path from "path";
/* const {
dependencies,
peerDependencies,
name,
version,
author,
keywords,
} = require("./package.json"); */
import dts from "npm-dts";
import { nodeExternalsPlugin } from "esbuild-node-externals";
import babel from "esbuild-plugin-babel";
const { dependencies, peerDependencies, name, version, author, keywords } =
JSON.parse(fs.readFileSync("./package.json"));
const esbuildOptions = {
// outfile: "dist/lib.js",
// outdir: "dist",
bundle: true,
minify: false,
// platform: "node",
// format: "esm",
sourcemap: true,
// plugins: [nodeExternalsPlugin()],
external: Object.keys(dependencies).concat(Object.keys(peerDependencies)),
};
async function build(files_) {
return await esbuild
.build({
target: "node14",
outfile: "dist/lib.js",
entryPoints: files_,
...esbuildOptions,
})
.catch(() => process.exit(1));
}
async function buildEsm(files_) {
return await esbuild
.build({
outfile: "dist/lib.esm.js",
format: "esm",
platform: "browser",
inject: ["./react-shim.js"],
entryPoints: files_,
plugins: [babel()],
...esbuildOptions,
})
.catch(() => process.exit(1));
}
async function buildCjs(files_) {
return await esbuild
.build({
outfile: "dist/lib.js",
format: "cjs",
platform: "browser",
inject: ["./react-shim.js"],
entryPoints: files_,
plugins: [babel()],
...esbuildOptions,
})
.catch(() => process.exit(1));
}
const files = ["src/lib.ts"];
buildEsm(files)
.then(() => buildCjs(files))
.then(() =>
new dts.Generator(
{
logLevel: "debug",
entry: "src/lib.ts",
output: "dist/lib.d.ts",
tsc: "-p tsconfig.build.json",
},
true,
true
)
.generate()
.then(() => console.log("create lib.d.ts"))
)
/* .then(() =>
fs.writeFileSync(
"dist/package.json",
JSON.stringify(
{
name,
version,
author,
// module: "lib.esm.js",
main: "lib.js",
typings: "lib.d.ts",
peerDependencies,
dependencies,
keywords,
},
null,
2
),
"utf-8"
)
) */
// .then(() => console.log("create package.json"))
// .then(() => fs.copyFileSync("README.md", "dist/README.md"))
.catch((err) => console.log(err))
.finally(() => process.exit(0));