-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.mjs
48 lines (42 loc) · 1.34 KB
/
esbuild.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
import * as esbuild from "esbuild"
import fs from "fs/promises"
const components = await fs.readdir("src/components")
const files = components.map(async (component) => {
if ((await fs.stat(`src/components/${component}`)).isDirectory()) {
return [`src/components/${component}/index.tsx`, `src/components/${component}/hookform.tsx`]
} else {
return []
}
})
const entryPoints = await Promise.all(files).then((tsxs) => tsxs.flat())
await esbuild.build({
entryPoints: entryPoints,
outdir: "dist",
outbase: "src",
format: "cjs",
platform: "node",
bundle: true,
minify: true,
external: ["react-dom", "react", "react-hook-form", "react-select", "react-datepicker"],
})
await esbuild.build({
entryPoints: ["src/index.ts"],
outfile: "dist/index.js",
format: "cjs",
platform: "node",
bundle: false,
minify: false,
})
await esbuild.build({
entryPoints: ["src/index.css"],
outfile: "dist/style.css",
bundle: true,
})
// const dtsDir = await fs.readdir("dist/components")
// dtsDir.forEach(async (dir) => {
// await fs.rename(`dist/components/${dir}/index.d.ts`, `dist/${dir}/index.d.ts`)
// await fs.rename(`dist/components/${dir}/hookform.d.ts`, `dist/${dir}/hookform.d.ts`)
// })
// await fs.rm("dist/components", { recursive: true })
await fs.rm("dist/hooks", { recursive: true })
await fs.rm("dist/utils", { recursive: true })