MCPcopy Create free account
hub / github.com/formkit/formkit / setupNuxtConfig

Function setupNuxtConfig

packages/cli/src/createApp.ts:485–579  ·  view source on GitHub ↗

* Sets up the Nuxt config with FormKit and Tailwind CSS 4. * Creates the main.css file and modifies nuxt.config.ts.

(dirName: string)

Source from the content-addressed store, hash-verified

483 * Creates the main.css file and modifies nuxt.config.ts.
484 */
485async function setupNuxtConfig(dirName: string) {
486 const projectPath = resolve(cwd(), `./${dirName}`)
487
488 // Create app/assets/css/main.css
489 const cssDir = resolve(projectPath, 'app/assets/css')
490 await mkdir(cssDir, { recursive: true })
491 await writeFile(
492 resolve(cssDir, 'main.css'),
493 `@import "tailwindcss";
494@source "../../../formkit.theme.ts";
495@source "../../../formkit.config.ts";
496
497body {
498 @apply bg-gray-100;
499}
500`
501 )
502
503 // Modify nuxt.config.ts
504 const nuxtConfigPath = resolve(projectPath, 'nuxt.config.ts')
505 let config = await readFile(nuxtConfigPath, 'utf-8')
506
507 // Add tailwindcss import at the top if not present
508 if (!config.includes('@tailwindcss/vite')) {
509 config = `import tailwindcss from "@tailwindcss/vite";\n\n${config}`
510 }
511
512 // Find the defineNuxtConfig call and modify it
513 // This regex captures the content inside defineNuxtConfig({ ... })
514 const configMatch = config.match(/defineNuxtConfig\(\s*\{([\s\S]*?)\}\s*\)/)
515
516 if (configMatch) {
517 let configContent = configMatch[1]
518
519 // Check if modules exists and add @formkit/nuxt
520 if (configContent.includes('modules:')) {
521 // Add to existing modules array
522 configContent = configContent.replace(
523 /modules:\s*\[([^\]]*)\]/,
524 (_match, modules) => {
525 const existingModules = modules.trim()
526 if (existingModules) {
527 return `modules: [\n '@formkit/nuxt',\n ${existingModules}\n ]`
528 }
529 return `modules: [\n '@formkit/nuxt',\n ]`
530 }
531 )
532 } else {
533 // Add modules array
534 configContent = addConfigProperty(configContent, `modules: [\n '@formkit/nuxt',\n ]`)
535 }
536
537 // Add css array if not present
538 if (!configContent.includes('css:')) {
539 configContent = addConfigProperty(configContent, `css: ['./app/assets/css/main.css']`)
540 }
541
542 // Add or merge vite config

Callers 1

createAppFunction · 0.85

Calls 1

addConfigPropertyFunction · 0.85

Tested by

no test coverage detected