-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
83 lines (74 loc) · 2.76 KB
/
tsup.config.ts
File metadata and controls
83 lines (74 loc) · 2.76 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { defineConfig, type Options } from 'tsup';
const NODE_TARGET = 'node20.19'; // Minimum Node version supported by Storybook 10
export default defineConfig(async () => {
// reading the three types of entries from package.json, which has the following structure:
// {
// ...
// "bundler": {
// "managerEntries": ["./src/manager.ts"],
// "previewEntries": ["./src/preview.ts", "./src/index.ts"]
// "nodeEntries": ["./src/preset.ts"]
// }
// }
const packageJson = (await import('./package.json', { with: { type: 'json' } })).default;
const {
bundler: { managerEntries = [], previewEntries = [], nodeEntries = [] },
} = packageJson;
const commonConfig: Options = {
/*
keep this line commented until https://github.com/egoist/tsup/issues/1270 is resolved
clean: options.watch ? false : true,
*/
clean: false,
format: ['esm'],
treeshake: true,
splitting: true,
/*
The following packages are provided by Storybook and should always be externalized
Meaning they shouldn't be bundled with the addon, and they shouldn't be regular dependencies either
*/
external: ['react', 'react-dom', '@storybook/icons'],
};
const configs: Options[] = [];
/*
manager entries are entries meant to be loaded into the manager UI
they'll have manager-specific packages externalized and they won't be usable in node
they won't have types generated for them as they're usually loaded automatically by Storybook
*/
if (managerEntries.length) {
configs.push({
...commonConfig,
entry: managerEntries,
platform: 'browser',
target: 'esnext', // we can use esnext for manager entries since Storybook will bundle the addon's manager entries again anyway
});
}
/*
preview entries are entries meant to be loaded into the preview iframe
they'll have preview-specific packages externalized and they won't be usable in node
they'll have types generated for them so they can be imported by users when setting up Portable Stories or using CSF factories
*/
if (previewEntries.length) {
configs.push({
...commonConfig,
entry: previewEntries,
platform: 'browser',
target: 'esnext', // we can use esnext for preview entries since the builders will bundle the addon's preview entries again anyway
dts: true,
});
}
/*
node entries are entries meant to be used in node-only
this is useful for presets, which are loaded by Storybook when setting up configurations
they won't have types generated for them as they're usually loaded automatically by Storybook
*/
if (nodeEntries.length) {
configs.push({
...commonConfig,
entry: nodeEntries,
platform: 'node',
target: NODE_TARGET,
});
}
return configs;
});