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

tsdown.config.ts

84 lines2.4 KB

1import { createRequire } from 'node:module'
2import { defineConfig } from 'tsdown'
3import solid from 'unplugin-solid/rolldown'
4​
5const require = createRequire(import.meta.url)
6​
7const solidBrowserIds: Record<string, string> = {
8 'solid-js/web': require.resolve('solid-js/web/dist/web.js'),
9 'solid-js/store': require.resolve('solid-js/store/dist/store.js'),
10 'solid-js/html': require.resolve('solid-js/html/dist/html.js'),
11 'solid-js/h': require.resolve('solid-js/h/dist/h.js'),
12 'solid-js': require.resolve('solid-js/dist/solid.js'),
14​
15const solidBrowserImports = () => ({
16 name: 'solid-browser-imports',
17 resolveId(id: string, importer?: string) {
18 // Resolve the browser runtime explicitly. This keeps Solid bundled in
19 // query-devtools, as it was with tsup-preset-solid, while keeping d.ts
20 // imports unchanged.
21 if (importer?.includes('.d.')) return undefined
22 const browserId = solidBrowserIds[id]
23 if (browserId) {
24 return { id: browserId, external: false }
25 }
26 return undefined
27 },
28})
29​
30const baseConfig = {
31 target: 'esnext',
32 platform: 'neutral' as const,
33 alias: {
34 'solid-transition-group': 'solid-transition-group/dist/index.js',
35 },
36 format: ['esm', 'cjs'] as ['esm', 'cjs'],
37 outDir: 'build',
38 fixedExtension: false,
39 // Published source needs these dependencies declared, but the compiled
40 // devtools must still bundle them with the Solid browser runtime.
41 deps: {
42 alwaysBundle: [/./],
43 dts: { alwaysBundle: [] },
44 },
45 inputOptions: {
46 // Keep package imports in declaration output. Runtime Solid imports are
47 // bundled from the browser files by solidBrowserImports above.
48 external: (id: string, importer?: string) =>
49 (id.startsWith('solid-js') && importer?.includes('.d.')) ||
50 (id === '@tanstack/query-core' && importer?.includes('.d.')),
51 },
53​
54const environment = (development: boolean) => ({
55 NODE_ENV: development ? 'development' : 'production',
56 PROD: !development,
57 DEV: development,
58 SSR: false,
59})
60​
61export default defineConfig([
62 {
63 ...baseConfig,
64 entry: { index: 'src/index.ts' },
65 clean: true,
66 dts: true,
67 env: environment(false),
68 minify: {
69 compress: {
70 dropConsole: true,
71 dropDebugger: true,
72 },
73 },
74 plugins: [solid(), solidBrowserImports()],
75 },
76 {
77 ...baseConfig,
78 entry: { dev: 'src/index.ts' },
79 clean: false,
80 dts: false,
81 env: environment(true),
82 plugins: [solid(), solidBrowserImports()],
83 },
84])