-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
81 lines (74 loc) · 2.17 KB
/
tsdown.config.ts
File metadata and controls
81 lines (74 loc) · 2.17 KB
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
import type { UserConfig } from 'tsdown';
const pkgName = 'react-querybuilder_chakra2';
export default (async options => {
const entryPoint = `src/index.tsx`;
const commonOptions = {
sourcemap: true,
platform: 'neutral',
dts: { oxc: true },
...options,
} satisfies UserConfig;
const productionOptions = {
minify: true,
define: { NODE_ENV: 'production' },
} satisfies UserConfig;
const opts: UserConfig[] = [
// ESM, standard bundler dev, embedded `process` references
{
...commonOptions,
entry: { [pkgName]: entryPoint },
format: 'esm',
clean: true,
},
// ESM, Webpack 4 support. Target ES2017 syntax to compile away optional chaining and spreads
{
...commonOptions,
entry: { [`${pkgName}.legacy-esm`]: entryPoint },
// ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
outExtensions: () => ({ js: '.js' }),
target: 'es2017',
format: 'esm',
},
// ESM for use in browsers. Minified, with `process` compiled away
{
...commonOptions,
...productionOptions,
entry: { [`${pkgName}.production`]: entryPoint },
format: 'esm',
outExtensions: () => ({ js: '.mjs' }),
},
// CJS development
{
...commonOptions,
entry: { [`${pkgName}.cjs.development`]: entryPoint },
format: 'cjs',
outDir: './dist/cjs/',
},
// CJS production
{
...commonOptions,
...productionOptions,
entry: { [`${pkgName}.cjs.production`]: entryPoint },
format: 'cjs',
outDir: './dist/cjs/',
onSuccess: async () => {
const prodfilename = `${pkgName}.cjs.production.js`;
const devfilename = `${pkgName}.cjs.development.js`;
await Promise.all([
Bun.write(
`dist/cjs/index.js`,
`'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./${prodfilename}');
} else {
module.exports = require('./${devfilename}');
}
`
),
Bun.write(`dist/cjs/index.d.ts`, `export * from './${devfilename}';`),
]);
},
},
];
return opts;
}) as (options: UserConfig) => Promise<UserConfig[]>;