forked from reduxjs/react-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
119 lines (115 loc) · 2.8 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
117
118
119
import { defineConfig, Options } from 'tsup'
import path from 'path'
import fs from 'fs'
function writeCommonJSEntry() {
fs.writeFileSync(
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')
}`
)
}
export default defineConfig((options) => {
const commonOptions: Partial<Options> = {
entry: {
'react-redux': 'src/index.ts',
},
sourcemap: true,
target: 'es2020',
...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,
},
// "Alternate renderers" entry point with a no-op batch
{
...commonOptions,
entry: {
'react-redux.alternate-renderers': 'src/alternate-renderers.ts',
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
},
// React Native requires a separate entry point for `"react-native"` batch dep
{
...commonOptions,
entry: {
'react-redux.react-native': 'src/react-native.ts',
},
format: ['esm'],
outExtension: () => ({ js: '.js' }),
},
// 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: () => {
writeCommonJSEntry()
},
},
]
})