import { defineConfig } from 'tsdown'; import { mkdir, writeFile } from 'node:fs/promises'; import path from 'node:path'; import { Scanner } from '@tailwindcss/oxide'; import { packageTranslationsPlugin } from '../shared/compile-package-translations.ts'; export default defineConfig({ format: 'esm', target: 'es2023', entry: [ './src/{index,i18n}.ts', './src/ui/{index,base,create-client}.tsx', './src/ui/asyncapi/index.tsx', './src/ui/asyncapi-base.tsx', './src/ui/client/index.tsx', './src/playground/client.tsx', './src/scalar/index.tsx', './src/server/index.tsx', './src/requests/generators/*.ts', ], unbundle: true, ignoreWatch: ['src/.translations/**'], dts: { sourcemap: false, }, sourcemap: false, plugins: [packageTranslationsPlugin()], async onSuccess() { await compileInline(); }, platform: 'browser', deps: { onlyBundle: [ 'fast-content-type-parse', '@fastify/deepmerge', '@scalar/openapi-upgrader', // for Vite RSC compatibility 'xml-js', 'ajv', 'fast-deep-equal', 'json-schema-traverse', 'fast-uri', ], neverBundle: [/^node:/, 'fs', /ajv(.+)\.d\.ts/], }, exports: { enabled: true, customExports(v) { v['./css/*'] = './css/*'; return v; }, }, }); async function compileInline() { await mkdir('css/generated', { recursive: true }); const scanner = new Scanner({ sources: [ { base: path.resolve('src'), pattern: '{playground,scalar,ui}/**/*.{ts,tsx}', negated: false, }, { base: path.resolve('src'), pattern: 'server/**/*.tsx', negated: false, }, ], }); await writeFile('css/generated/shared.css', namesToFile(scanner.scan())); console.log('generated CSS files'); } function namesToFile(names: string[]) { return `@source inline(${JSON.stringify(names.join(' '))});`; }