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

vite.config.ts

83 lines2.1 KB

1import path from 'node:path'
2import { defineConfig } from 'vitest/config'
3import solid from 'vite-plugin-solid'
4import tailwindcss from '@tailwindcss/vite'
5import { playwright } from '@vitest/browser-playwright'
6import packageJson from './package.json' with { type: 'json' }
7​
8const normalizeChunkPath = (id: string | null | undefined) =>
9 id?.replaceAll(path.sep, '/')
10​
11const componentsEntry = normalizeChunkPath(
12 path.resolve(import.meta.dirname, './src/components/index.tsx'),
14​
15const isBareImport = (id: string) =>
16 !id.startsWith('.') &&
17 !path.isAbsolute(id) &&
18 !id.startsWith('\0') &&
19 !id.startsWith('@/') &&
20 id !== '@'
21​
22export default defineConfig({
23 plugins: [
24 solid({ hot: false }),
25 tailwindcss(),
26 {
27 name: 'form-devtools-css-entry',
28 renderChunk(code, chunk) {
29 const isComponentsChunk =
30 normalizeChunkPath(chunk.facadeModuleId) === componentsEntry ||
31 Object.keys(chunk.modules).some(
32 (moduleId) => normalizeChunkPath(moduleId) === componentsEntry,
33 )
34​
35 if (!isComponentsChunk) {
36 return null
37 }
38​
39 return `import './style.css';\n${code}`
40 },
41 },
42 ],
43 resolve: {
44 alias: {
45 '@': path.resolve(import.meta.dirname, './src'),
46 },
47 },
48 build: {
49 outDir: 'dist',
50 emptyOutDir: true,
51​
52 lib: {
53 entry: {
54 index: 'src/index.ts',
55 production: 'src/production.ts',
56 },
57 formats: ['es'],
58 fileName: (_format, entryName) => `${entryName}.js`,
59 cssFileName: 'style',
60 },
61​
62 rolldownOptions: {
63 external: isBareImport,
64 },
65 },
66 test: {
67 name: packageJson.name,
68 dir: './tests',
69 watch: false,
70 globals: true,
71 // Override vite-plugin-solid's jsdom default; tests run in the browser.
72 environment: 'node',
73 browser: {
74 enabled: true,
75 // CI runners (ubuntu-latest) ship with Google Chrome preinstalled, so
76 // use it rather than downloading playwright's own browser build
77 provider: playwright(
78 process.env.CI ? { launchOptions: { channel: 'chrome' } } : {},
79 ),
80 instances: [{ browser: 'chromium', headless: true }],
81 },
82 },
83})