-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
62 lines (57 loc) · 1.21 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
import fs from "node:fs/promises"
import { defineConfig, Options } from "tsup"
export default defineConfig((options) => {
const commonOptions: Partial<Options> = {
entry: {
immer: "src/immer.js",
},
loader: {
".js": "ts",
},
platform: "neutral",
sourcemap: true,
...options,
}
const productionOptions: Partial<Options> = {
entry: {
"immer.production": "src/immer.js",
},
minify: true,
replaceNodeEnv: true,
}
return [
{
...commonOptions,
format: ["esm", "cjs"],
dts: true,
},
{
...commonOptions,
format: "esm",
target: "es2017",
legacyOutput: true,
},
{
...commonOptions,
...productionOptions,
format: ["esm", "cjs"],
async onSuccess() {
await Promise.all([
fs.copyFile(
"node_modules/immer/dist/cjs/index.js.flow",
"dist/index.js.flow",
),
fs.writeFile(
"dist/index.js",
`"use strict";
if (process.env.NODE_ENV === "production") {
module.exports = require("./immer.production.js");
} else {
module.exports = require("./immer.js");
}`,
),
])
},
},
]
})