-
Notifications
You must be signed in to change notification settings - Fork 1
/
tsup.config.js
105 lines (97 loc) · 2.7 KB
/
tsup.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
95
96
97
98
99
100
101
102
103
104
105
const { defineConfig } = require("tsup");
const { elements, layouts } = require("./registry");
const elementEntries = elements.reduce((entries, elementName) => {
entries[`${elementName}/index`] = `elements/${elementName}/index.ts`;
return entries;
}, {});
const layoutEntries = layouts.reduce((entries, layoutName) => {
entries[`${layoutName}/index`] = `layout/${layoutName}/index.ts`;
return entries;
}, {});
function chunkEntries(entries, chunkSize) {
return Object.entries(entries).reduce((resultArray, [key, value], index) => {
const chunkIndex = Math.floor(index / chunkSize);
if (!resultArray[chunkIndex]) {
resultArray[chunkIndex] = {};
}
resultArray[chunkIndex][key] = value;
return resultArray;
}, []);
}
function createConfigForGroup(entries, name) {
return defineConfig({
name: name || "Grouped Entries",
clean: false,
sourcemap: true,
dts: true,
splitting: false,
treeshake: false,
minify: false,
target: "es2019",
format: ["cjs", "esm"],
banner: { js: '"use client";' },
entry: entries,
tsconfig: "./tsconfig.json",
external: [
"react",
"react-dom",
"@radix-ui/react-toast",
"react-day-picker",
],
});
}
const groupedElementEntries = chunkEntries(elementEntries, 3);
const groupedLayoutEntries = chunkEntries(layoutEntries, 3);
const groupedElements = groupedElementEntries.map((group, i) =>
createConfigForGroup(group, `Build Elements Group - ${i}`),
);
const groupedLayout = groupedLayoutEntries.map((group, i) =>
createConfigForGroup(group, `Build Layout Group - ${i}`),
);
const buildAllConfig = defineConfig({
name: "Build All",
clean: false,
dts: true,
target: "es2019",
entry: { index: "index.ts" },
format: ["cjs", "esm"],
banner: { js: '"use client";' },
});
const buildCoreConfig = defineConfig({
name: "Build Core",
clean: false,
dts: true,
target: "es2019",
format: ["cjs", "esm"],
banner: { js: '"use client";' },
entry: {
// CORE
"types/index": "types/index.ts",
"hooks/index": "hooks/index.ts",
"blocks/index": "blocks/index.ts",
"layout/index": "layout/index.ts",
"elements/index": "elements/index.ts",
},
});
const buildBlocksConfig = defineConfig({
name: "Build Blocks",
clean: false,
dts: true,
target: "es2019",
format: ["cjs", "esm"],
banner: { js: '"use client";' },
entry: {
// BLOCKS
"blocks/misc/index": "blocks/misc/index.ts",
"blocks/auth/index": "blocks/auth/index.ts",
"blocks/pricing/index": "blocks/pricing/index.ts",
"blocks/feedback/index": "blocks/feedback/index.ts",
},
});
module.exports = {
groupedElements,
groupedLayout,
buildAllConfig,
buildCoreConfig,
buildBlocksConfig,
};