-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
94 lines (88 loc) · 2.04 KB
/
esbuild.config.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
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
// import chokidar from "chokidar";
const esbuild = require("esbuild");
const fs = require("fs");
const {
dependencies,
peerDependencies,
name,
version,
author,
keywords,
repository,
} = require("./package.json");
const { Generator } = require("npm-dts");
const { nodeExternalsPlugin } = require("esbuild-node-externals");
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 buildEsm(files_) {
return await esbuild
.build({
outfile: "dist/index.esm.js",
format: "esm",
platform: "node",
target: "esnext",
// inject: ["./react-shim.js"],
entryPoints: files_,
...esbuildOptions,
})
.catch(() => process.exit(1));
}
async function buildCjs(files_) {
return await esbuild
.build({
outfile: "dist/index.js",
format: "cjs",
platform: "node",
target: "esnext",
// inject: ["./react-shim.js"],
entryPoints: files_,
...esbuildOptions,
})
.catch(() => process.exit(1));
}
const files = ["src/index.ts"];
buildEsm(files)
.then(() => buildCjs(files))
.then(() =>
new Generator({
entry: "index.ts",
output: "dist/index.d.ts",
})
.generate()
.then(() => console.log("create index.d.ts"))
)
/* .then(() =>
fs.writeFileSync(
"dist/package.json",
JSON.stringify(
{
name,
version,
author,
// module: "lib.esm.js",
main: "index.js",
typings: "index.d.ts",
peerDependencies,
dependencies,
keywords,
repository,
},
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));