Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

tsdown.config.ts

58 lines1.3 KB

1import { defineConfig } from 'tsdown'
2import solid from 'unplugin-solid/rolldown'
3​
4const baseConfig = {
5 target: 'esnext',
6 platform: 'browser' as const,
7 format: ['esm', 'cjs'] as ['esm', 'cjs'],
8 outDir: 'build',
9 fixedExtension: false,
11​
12const environment = (development: boolean) => ({
13 NODE_ENV: development ? 'development' : 'production',
14 PROD: !development,
15 DEV: development,
16 SSR: false,
17})
18​
19const compiledConfig = (
20 entry: Record<string, string>,
21 development: boolean,
22 clean: boolean,
23) => ({
24 ...baseConfig,
25 entry,
26 clean,
27 dts: !development,
28 env: environment(development),
29 ...(development
30 ? {}
31 : {
32 minify: {
33 compress: {
34 dropConsole: true,
35 dropDebugger: true,
36 },
37 },
38 }),
39 plugins: [solid()],
40})
41​
42const jsxConfig = (entry: Record<string, string>, development: boolean) => ({
43 ...baseConfig,
44 entry,
45 format: 'esm' as const,
46 clean: false,
47 dts: false,
48 env: environment(development),
49 outExtensions: () => ({ js: '.jsx' }),
50 plugins: [],
51})
52​
53export default defineConfig([
54 compiledConfig({ index: 'src/index.tsx' }, false, true),
55 jsxConfig({ index: 'src/index.tsx' }, false),
56 compiledConfig({ dev: 'src/index.tsx' }, true, false),
57 jsxConfig({ dev: 'src/index.tsx' }, true),
58])