-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tsup.config.ts
68 lines (66 loc) · 1.55 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
import { defineConfig, Options } from "tsup";
import { dependencies } from "./package.json";
export default defineConfig((options) => {
const commonOptions: Partial<Options> = {
clean: true,
entry: {
index: "src/index.ts",
},
sourcemap: true,
...options,
};
return [
// Modern ESM
{
...commonOptions,
format: ["esm"],
outExtension: () => ({ js: ".mjs" }),
dts: true,
outDir: "./lib/esm/",
},
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
{
...commonOptions,
entry: {
"index.legacy-esm": "src/index.ts",
},
format: ["esm"],
outExtension: () => ({ js: ".js" }),
target: "es2017",
outDir: "./lib/esm/",
},
// Browser-ready ESM, production + minified
{
...commonOptions,
entry: {
"index.browser": "src/index.ts",
},
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
format: ["esm"],
outExtension: () => ({ js: ".js" }),
dts: true,
minify: true,
noExternal: Object.keys(dependencies),
skipNodeModulesBundle: false,
splitting: false,
outDir: "./lib/esm/",
},
// CJS
{
...commonOptions,
format: ["cjs"],
outExtension: () => ({ js: ".cjs" }),
dts: true,
outDir: "./lib/cjs/",
},
// CJS old extension
{
...commonOptions,
format: ["cjs"],
outExtension: () => ({ js: ".js" }),
outDir: "./lib/cjs/",
},
] as Options[];
});