Skip to content

Commit 247a41e

Browse files
committed
Add initial tsup config
1 parent 146e5dd commit 247a41e

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

tsup.config.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { defineConfig, Options } from 'tsup'
2+
3+
import path from 'path'
4+
import fs from 'fs'
5+
6+
function writeCommonJSEntry() {
7+
fs.writeFileSync(
8+
path.join('dist/cjs/', 'index.js'),
9+
`'use strict'
10+
if (process.env.NODE_ENV === 'production') {
11+
module.exports = require('./react-redux.production.min.cjs')
12+
} else {
13+
module.exports = require('./react-redux.development.cjs')
14+
}`
15+
)
16+
}
17+
18+
export default defineConfig((options) => {
19+
const commonOptions: Partial<Options> = {
20+
entry: {
21+
'react-redux': 'src/index.ts',
22+
},
23+
sourcemap: true,
24+
target: 'es2020',
25+
...options,
26+
}
27+
28+
return [
29+
// Standard ESM, embedded `process.env.NODE_ENV` checks
30+
{
31+
...commonOptions,
32+
format: ['esm'],
33+
outExtension: () => ({ js: '.mjs' }),
34+
dts: true,
35+
clean: true,
36+
},
37+
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
38+
{
39+
...commonOptions,
40+
entry: {
41+
'react-redux.legacy-esm': 'src/index.ts',
42+
},
43+
target: 'es2017',
44+
format: ['esm'],
45+
outExtension: () => ({ js: '.js' }),
46+
},
47+
// Browser-ready ESM, production + minified
48+
{
49+
...commonOptions,
50+
entry: {
51+
'react-redux.browser': 'src/index.ts',
52+
},
53+
define: {
54+
'process.env.NODE_ENV': JSON.stringify('production'),
55+
},
56+
format: ['esm'],
57+
outExtension: () => ({ js: '.mjs' }),
58+
minify: true,
59+
},
60+
// "Alternate renderers" entry point with a no-op batch
61+
{
62+
...commonOptions,
63+
entry: {
64+
'react-redux.alternate-renderers': 'src/alternate-renderers.ts',
65+
},
66+
format: ['esm'],
67+
outExtension: () => ({ js: '.mjs' }),
68+
},
69+
// CJS development
70+
{
71+
...commonOptions,
72+
entry: {
73+
'react-redux.development': 'src/index.ts',
74+
},
75+
define: {
76+
'process.env.NODE_ENV': JSON.stringify('development'),
77+
},
78+
format: 'cjs',
79+
outDir: './dist/cjs/',
80+
outExtension: () => ({ js: '.cjs' }),
81+
},
82+
// CJS production
83+
{
84+
...commonOptions,
85+
entry: {
86+
'react-redux.production.min': 'src/index.ts',
87+
},
88+
define: {
89+
'process.env.NODE_ENV': JSON.stringify('production'),
90+
},
91+
format: 'cjs',
92+
outDir: './dist/cjs/',
93+
outExtension: () => ({ js: '.cjs' }),
94+
minify: true,
95+
onSuccess: () => {
96+
writeCommonJSEntry()
97+
},
98+
},
99+
]
100+
})

0 commit comments

Comments
 (0)