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

tsdown.config.ts

88 lines2.5 KB

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