-
Notifications
You must be signed in to change notification settings - Fork 672
/
tsup.config.ts
103 lines (98 loc) · 2.28 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fs from 'node:fs/promises'
import path from 'node:path'
import type { Options } from 'tsup'
import { defineConfig } from 'tsup'
async function writeCommonJSEntry() {
await fs.writeFile(
path.join('dist/cjs/', 'index.js'),
`'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./reselect.production.min.cjs')
} else {
module.exports = require('./reselect.development.cjs')
}`
)
}
export default defineConfig((options): Options[] => {
const commonOptions: Options = {
entry: {
reselect: 'src/index.ts'
},
sourcemap: true,
target: ['esnext'],
clean: true,
...options
}
return [
{
...commonOptions,
name: 'Modern ESM',
target: ['esnext'],
format: ['esm'],
outExtension: () => ({ js: '.mjs' })
},
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
// and optional chaining compiled away
{
...commonOptions,
name: 'Legacy ESM, Webpack 4',
entry: {
'reselect.legacy-esm': 'src/index.ts'
},
format: ['esm'],
outExtension: () => ({ js: '.js' }),
target: ['es2017']
},
// Meant to be served up via CDNs like `unpkg`.
{
...commonOptions,
name: 'Browser-ready ESM',
entry: {
'reselect.browser': 'src/index.ts'
},
platform: 'browser',
env: {
NODE_ENV: 'production'
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
minify: true
},
{
...commonOptions,
name: 'CJS Development',
entry: {
'reselect.development': 'src/index.ts'
},
env: {
NODE_ENV: 'development'
},
format: ['cjs'],
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' })
},
{
...commonOptions,
name: 'CJS production',
entry: {
'reselect.production.min': 'src/index.ts'
},
env: {
NODE_ENV: 'production'
},
format: ['cjs'],
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' }),
minify: true,
onSuccess: async () => {
await writeCommonJSEntry()
}
},
{
...commonOptions,
name: 'CJS Type Definitions',
format: ['cjs'],
dts: { only: true }
}
]
})