2026-08-06 09f01778d5a034e2af50ae05da8908f7b6a871c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Generic Vite registry entry: a bundled app with a real `index.html` entry
 * and no framework-specific document ownership. React, Vue, Solid, Preact and
 * a plain TanStack Router SPA all land here — the marker-wrapped script block
 * goes straight into the HTML entry.
 *
 * This is the entry that catches everything with a bundler config; only
 * static-html sits below it.
 */
 
import { fileExists, findConfigFile, hasAnyDependency } from './detect-utils.mjs';
 
const VITE_CONFIG_RE = /^vite\.config\.(?:js|mjs|cjs|ts|mts|cts)$/;
 
export function detectViteProject(cwd = process.cwd()) {
  const configFile = findConfigFile(cwd, VITE_CONFIG_RE);
  if (configFile) return { configFile, via: 'config' };
  if (hasAnyDependency(cwd, ['vite'])) return { configFile: null, via: 'package' };
  // A zero-config Vite app is index.html + package.json, the same pair
  // roots.mjs treats as an app root.
  if (fileExists(cwd, 'index.html') && fileExists(cwd, 'package.json')) {
    return { configFile: null, via: 'zero-config' };
  }
  return null;
}
 
export const viteGeneric = {
  name: 'vite-generic',
 
  detect(cwd) {
    return detectViteProject(cwd);
  },
 
  inject: { kind: 'tag' },
 
  source: {
    extensions: ['.tsx', '.jsx'],
    preview: 'source',
    styleMode: 'scoped',
    commentSyntax: 'jsx',
  },
};