-
-
Notifications
You must be signed in to change notification settings - Fork 850
/
tsup.config.ts
93 lines (88 loc) · 1.91 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
import {defineConfig, Options} from "tsup"
import fs from "fs"
export default defineConfig(options => {
const commonOptions: Partial<Options> = {
entry: {
immer: "src/immer.ts"
},
sourcemap: true,
...options
}
const productionOptions = {
minify: true,
esbuildOptions(options, _context) {
options.mangleProps = /_$/
},
define: {
"process.env.NODE_ENV": JSON.stringify("production")
}
}
return [
// ESM, standard bundler dev, embedded `process` references
{
...commonOptions,
format: ["esm"],
dts: true,
clean: true,
sourcemap: true,
onSuccess() {
// Support Flow types
fs.copyFileSync("src/types/index.js.flow", "dist/cjs/index.js.flow")
}
},
// ESM, Webpack 4 support. Target ES2018 syntax to compile away optional chaining and spreads
{
...commonOptions,
entry: {
"immer.legacy-esm": "src/immer.ts"
},
// ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
outExtension: () => ({js: ".js"}),
target: "es2017",
format: ["esm"],
sourcemap: true
},
// ESM for use in browsers. Minified, with `process` compiled away
{
...commonOptions,
...productionOptions,
entry: {
"immer.production": "src/immer.ts"
},
format: ["esm"],
outExtension: () => ({js: ".mjs"})
},
// CJS development
{
...commonOptions,
entry: {
"immer.cjs.development": "src/immer.ts"
},
format: "cjs",
outDir: "./dist/cjs/"
},
// CJS production
{
...commonOptions,
...productionOptions,
entry: {
"immer.cjs.production": "src/immer.ts"
},
format: "cjs",
outDir: "./dist/cjs/",
onSuccess: () => {
// Write the CJS index file
fs.writeFileSync(
"dist/cjs/index.js",
`
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./immer.cjs.production.js')
} else {
module.exports = require('./immer.cjs.development.js')
}`
)
}
}
]
})