-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tsup.config.ts
77 lines (67 loc) · 1.85 KB
/
tsup.config.ts
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
import { defineConfig, type Options } from 'tsup'
import { readFile } from 'fs/promises'
import { globalPackages as globalManagerPackages } from '@storybook/manager/globals'
import { globalPackages as globalPreviewPackages } from '@storybook/preview/globals'
// The current browsers supported by Storybook v7
const BROWSER_TARGET: Options['target'] = ['chrome100', 'safari15', 'firefox91']
const NODE_TARGET: Options['target'] = ['node18']
type BundlerConfig = {
bundler?: {
exportEntries?: string[]
managerEntries?: string[]
previewEntries?: string[]
}
}
export default defineConfig(async options => {
const packageJson = (await readFile('./package.json', 'utf8').then(
JSON.parse,
)) as BundlerConfig
const {
bundler: {
exportEntries = [],
managerEntries = [],
previewEntries = [],
} = {},
} = packageJson
const commonConfig: Options = {
splitting: false,
minify: !options.watch,
treeshake: true,
sourcemap: true,
clean: true,
}
const configs: Options[] = []
if (exportEntries.length) {
configs.push({
...commonConfig,
entry: exportEntries,
dts: { resolve: true },
format: ['esm', 'cjs'],
target: [...BROWSER_TARGET, ...NODE_TARGET],
platform: 'neutral',
external: [...globalManagerPackages, ...globalPreviewPackages],
})
}
if (managerEntries.length) {
configs.push({
...commonConfig,
entry: managerEntries,
format: ['esm'],
target: BROWSER_TARGET,
platform: 'browser',
external: globalManagerPackages,
})
}
if (previewEntries.length) {
configs.push({
...commonConfig,
entry: previewEntries,
dts: { resolve: true },
format: ['esm', 'cjs'],
target: BROWSER_TARGET,
platform: 'browser',
external: globalPreviewPackages,
})
}
return configs
})