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

tsdown.config.ts

67 lines1.6 KB

1import { transformAsync } from '@babel/core'
2// @ts-expect-error - Ships no type declarations
3import ts from '@babel/preset-typescript'
4// @ts-expect-error - Ships no type declarations
5import solidPlugin from '@solidjs/babel-plugin'
6import { defineConfig } from 'tsdown'
7import type { Rolldown, UserConfig } from 'tsdown'
8​
9// Compiles JSX with the Solid 2.0 compiler; 'unplugin-solid' ships the Solid 1.x one.
10const solid = (): Rolldown.Plugin => ({
11 name: 'solid-v2',
12 transform: {
13 filter: { id: /\.[jt]sx$/ },
14 async handler(code, id) {
15 const result = await transformAsync(code, {
16 presets: [[ts, {}]],
17 plugins: [[solidPlugin, { generate: 'dom' }]],
18 filename: id,
19 sourceMaps: true,
20 })
21 if (result?.code == null) {
22 throw new Error(`Babel returned no code for ${id}`)
23 }
24 return { code: result.code, map: result.map, moduleType: 'js' }
25 },
26 },
27})
28​
29const baseConfig: UserConfig = {
30 target: 'esnext',
31 platform: 'browser',
32 format: ['esm', 'cjs'],
33 outDir: 'build',
34 fixedExtension: false,
36​
37const environment = (development: boolean) => ({
38 NODE_ENV: development ? 'development' : 'production',
39 PROD: !development,
40 DEV: development,
41 SSR: false,
42})
43​
44export default defineConfig([
45 {
46 ...baseConfig,
47 entry: { index: 'src/index.ts' },
48 clean: true,
49 dts: true,
50 env: environment(false),
51 minify: {
52 compress: {
53 dropConsole: true,
54 dropDebugger: true,
55 },
56 },
57 plugins: [solid()],
58 },
59 {
60 ...baseConfig,
61 entry: { dev: 'src/index.ts' },
62 clean: false,
63 dts: false,
64 env: environment(true),
65 plugins: [solid()],
66 },
67])