|
| 1 | +import { z } from 'zod'; |
| 2 | + |
| 3 | +export const transformSchema = z.object({ |
| 4 | + formats: z.string().array().optional(), |
| 5 | + excludes: z.union([ |
| 6 | + z.string(), |
| 7 | + z.array(z.string()), |
| 8 | + ]).optional(), |
| 9 | +}); |
| 10 | + |
| 11 | +export const bundleSchema = z.object({ |
| 12 | + name: z.string().optional(), |
| 13 | + outputDir: z.string().optional(), |
| 14 | + modes: z.enum(['production', 'development']).array().optional(), |
| 15 | + formats: z.string().array().optional(), |
| 16 | + externals: z.union([ |
| 17 | + z.boolean(), |
| 18 | + z.record(z.string()), |
| 19 | + ]).optional(), |
| 20 | + minify: z.union([ |
| 21 | + z.boolean(), |
| 22 | + z.object({ |
| 23 | + js: z.union([z.boolean(), z.function()]), |
| 24 | + css: z.union([z.boolean(), z.function()]), |
| 25 | + }), |
| 26 | + ]).optional(), |
| 27 | + polyfill: z.union([ |
| 28 | + z.literal(false), |
| 29 | + z.enum(['entry', 'usage']), |
| 30 | + ]).optional(), |
| 31 | + compileDependencies: z.union([ |
| 32 | + z.boolean(), |
| 33 | + z.union([z.string(), z.instanceof(RegExp)]).array(), |
| 34 | + ]).optional(), |
| 35 | + browser: z.boolean().optional(), |
| 36 | +}); |
| 37 | + |
| 38 | +export const userConfigSchema = z.object({ |
| 39 | + entry: z.union([ |
| 40 | + z.string(), |
| 41 | + z.string().array(), |
| 42 | + z.record(z.string()), |
| 43 | + ]).optional(), |
| 44 | + alias: z.record(z.string()).optional(), |
| 45 | + define: z.record(z.union([ |
| 46 | + z.string(), |
| 47 | + z.boolean(), |
| 48 | + z.number(), |
| 49 | + z.null(), |
| 50 | + z.record(z.any()), |
| 51 | + ])).optional(), |
| 52 | + sourceMaps: z.union([ |
| 53 | + z.boolean(), |
| 54 | + z.enum(['inline']), |
| 55 | + ]).optional(), |
| 56 | + generateTypeForJs: z.boolean().optional(), |
| 57 | + jsxRuntime: z.enum(['classic', 'automatic']).optional(), |
| 58 | + plugins: z.any().array().optional(), |
| 59 | + |
| 60 | + transform: transformSchema.optional(), |
| 61 | + bundle: bundleSchema.optional(), |
| 62 | + declaration: z.union([ |
| 63 | + z.boolean(), |
| 64 | + z.object({ |
| 65 | + outputMode: z.enum(['multi', 'unique']).optional(), |
| 66 | + }), |
| 67 | + ]), |
| 68 | +}); |
| 69 | + |
| 70 | +export type UserConfig = z.infer<typeof userConfigSchema>; |
0 commit comments