-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
tsup.config.ts
116 lines (110 loc) · 2.64 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
104
105
106
107
108
109
110
111
112
113
114
115
116
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('./react-redux.production.min.cjs')
} else {
module.exports = require('./react-redux.development.cjs')
}`,
)
}
const tsconfig = 'tsconfig.build.json' satisfies Options['tsconfig']
export default defineConfig((options): Options[] => {
const commonOptions: Options = {
entry: {
'react-redux': 'src/index.ts',
},
sourcemap: true,
clean: true,
target: ['esnext'],
tsconfig,
...options,
}
return [
// Standard ESM, embedded `process.env.NODE_ENV` checks
{
...commonOptions,
name: 'Modern ESM',
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
},
{
...commonOptions,
name: 'ESM for RSC',
entry: {
rsc: 'src/index-rsc.ts',
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: false,
},
// 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: {
'react-redux.legacy-esm': 'src/index.ts',
},
target: ['es2017'],
format: ['esm'],
outExtension: () => ({ js: '.js' }),
},
// Meant to be served up via CDNs like `unpkg`.
{
...commonOptions,
name: 'Browser-ready ESM',
entry: {
'react-redux.browser': 'src/index.ts',
},
platform: 'browser',
env: {
NODE_ENV: 'production',
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
minify: true,
},
{
...commonOptions,
name: 'CJS Development',
entry: {
'react-redux.development': 'src/index.ts',
},
env: {
NODE_ENV: 'development',
},
format: ['cjs'],
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' }),
},
{
...commonOptions,
name: 'CJS production',
entry: {
'react-redux.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 },
},
]
})