forked from thesysdev/openui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
66 lines (62 loc) · 2.11 KB
/
tsdown.config.ts
File metadata and controls
66 lines (62 loc) · 2.11 KB
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
import { existsSync, readdirSync, statSync } from "fs";
import { join } from "path";
import { defineConfig } from "tsdown";
import type { Plugin } from "rolldown";
// Rewrite external import paths in ESM output so they are fully-specified.
// webpack 5 (CRA) treats .mjs as strict ESM and requires explicit extensions.
const fixEsmExternalPaths: Plugin = {
name: "fix-esm-external-paths",
renderChunk(code: string) {
const result = code
.replace(/from "lodash-es\/([^"]+?)(?:\.js)?"/g, 'from "lodash-es/$1.js"')
.replace(
/"react-syntax-highlighter\/dist\/cjs\/styles\/prism"/g,
'"react-syntax-highlighter/dist/cjs/styles/prism/index.js"',
);
return { code: result };
},
};
const componentEntries = Object.fromEntries(
readdirSync("src/components")
.filter(
(dir) =>
statSync(join("src/components", dir)).isDirectory() &&
existsSync(join("src/components", dir, "index.ts")),
)
.map((dir) => [`components/${dir}/index`, `src/components/${dir}/index.ts`]),
);
const shared = {
dts: false,
sourcemap: true,
target: "es2022",
outDir: "dist",
clean: false,
deps: {
neverBundle: [/^[^./]/, /\.scss$/, /\.css$/],
},
} satisfies Parameters<typeof defineConfig>[0];
export default defineConfig([
// Main index — CJS + bundled .d.cts
{ ...shared, format: ["cjs"], dts: true, entry: { index: "src/index.ts" } },
// Main index — ESM + bundled .d.mts
{ ...shared, format: ["esm"], dts: true, entry: { index: "src/index.ts" }, plugins: [fixEsmExternalPaths] },
// genui-lib — CJS + .d.cts (own outDir so dts lands at dist/genui-lib/index.d.cts)
{
...shared,
format: ["cjs"],
dts: true,
outDir: "dist/genui-lib",
entry: { index: "src/genui-lib/index.ts" },
},
// genui-lib — ESM + .d.mts (own outDir so dts lands at dist/genui-lib/index.d.mts)
{
...shared,
format: ["esm"],
dts: true,
outDir: "dist/genui-lib",
entry: { index: "src/genui-lib/index.ts" },
plugins: [fixEsmExternalPaths],
},
// Individual components — CJS only
{ ...shared, format: ["cjs"], entry: componentEntries },
]);