forked from reduxjs/react-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
104 lines (100 loc) · 2.44 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
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,
target: 'es2020',
tsconfig,
...options,
}
return [
// Standard ESM, embedded `process.env.NODE_ENV` checks
{
...commonOptions,
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: true,
clean: true,
},
// ESM for RSC
{
...commonOptions,
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
{
...commonOptions,
entry: {
'react-redux.legacy-esm': 'src/index.ts',
},
target: 'es2017',
format: ['esm'],
outExtension: () => ({ js: '.js' }),
},
// Browser-ready ESM, production + minified
{
...commonOptions,
entry: {
'react-redux.browser': 'src/index.ts',
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
minify: true,
},
// CJS development
{
...commonOptions,
entry: {
'react-redux.development': 'src/index.ts',
},
define: {
'process.env.NODE_ENV': JSON.stringify('development'),
},
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' }),
},
// CJS production
{
...commonOptions,
entry: {
'react-redux.production.min': 'src/index.ts',
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' }),
minify: true,
onSuccess: async () => {
await writeCommonJSEntry()
},
},
]
})