forked from darkroomengineering/lenis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
86 lines (78 loc) · 1.87 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
78
79
80
81
82
83
84
85
86
import { defineConfig, type Options } from 'tsup'
const OUT_DIR = 'dist'
function makeBuildOptions(
fileName: string,
entryPoint: string,
format?: 'esm' | 'browser',
overwrites: Options = {}
): Options[] {
const options = {
entryPoints: { [fileName]: entryPoint },
format: 'esm',
outDir: OUT_DIR,
platform: 'browser',
target: 'es2022',
cjsInterop: false,
dts: true,
sourcemap: true,
external: ['react', 'vue', 'lenis'],
outExtension: () =>
format === 'esm' ? { js: '.mjs', dts: '.d.ts' } : { js: '.js' },
...overwrites,
} satisfies Options
const minifyOptions = {
...options,
minify: true,
outExtension: () => ({ js: '.min.js' }),
...overwrites,
} satisfies Options
return format === 'esm' ? [options] : [options, minifyOptions]
}
// Builds
export const coreESMOptions = makeBuildOptions(
'lenis',
'packages/core/index.ts',
'esm'
)
const coreBrowserOptions = makeBuildOptions(
'lenis',
'packages/core/browser.ts',
'browser',
{ dts: false }
)
const coreCSSOptions = makeBuildOptions(
'lenis',
'packages/core/lenis.css',
undefined,
{ dts: false, sourcemap: false, minify: true }
)
const snapESMOptions = makeBuildOptions(
'lenis-snap',
'packages/snap/index.ts',
'esm'
)
const snapBrowserOptions = makeBuildOptions(
'lenis-snap',
'packages/snap/browser.ts',
'browser',
{ dts: false }
)
const reactOptions = makeBuildOptions(
'lenis-react',
'packages/react/index.ts',
'esm',
{ banner: { js: '"use client";' } }
)
const vueOptions = makeBuildOptions('lenis-vue', 'packages/vue/index.ts', 'esm')
export default defineConfig(() => {
console.log(`\x1b[31mLNS\x1b[0m\x1b[1m Building all packages\x1b[0m\n`)
return [
...coreESMOptions,
...coreBrowserOptions,
...coreCSSOptions,
...snapESMOptions,
...snapBrowserOptions,
...reactOptions,
...vueOptions,
]
})