diff --git a/apps/www/src/content/docs/installation/nuxt.md b/apps/www/src/content/docs/installation/nuxt.md index 851ba6685..6031877db 100644 --- a/apps/www/src/content/docs/installation/nuxt.md +++ b/apps/www/src/content/docs/installation/nuxt.md @@ -49,6 +49,8 @@ export default defineNuxtConfig({ }) ``` +Note that if you prefer not to install the TailwindCSS module, please set `suppressMissingModuleWarning` to `true` in module options. + ### Add `Nuxt` module
@@ -196,7 +198,12 @@ export default defineNuxtConfig({ * Directory that the component lives in. * @default "./components/ui" */ - componentDir: './components/ui' + componentDir: './components/ui', + /** + * Suppress warning about missing modules + * @default false + */ + suppressMissingModuleWarning: boolean } }) ``` diff --git a/packages/module/src/module.ts b/packages/module/src/module.ts index 8ee3dfbe2..423bcdc02 100644 --- a/packages/module/src/module.ts +++ b/packages/module/src/module.ts @@ -16,6 +16,11 @@ export interface ModuleOptions { * @default "./components/ui" */ componentDir?: string + /** + * Suppress warning about missing modules + * @default false + */ + suppressMissingModuleWarning?: boolean } export default defineNuxtModule({ @@ -26,8 +31,9 @@ export default defineNuxtModule({ defaults: { prefix: '', componentDir: './components/ui', + suppressMissingModuleWarning: false, }, - async setup({ prefix, componentDir }, nuxt) { + async setup({ prefix, componentDir, suppressMissingModuleWarning }, nuxt) { const COMPONENT_DIR_PATH = componentDir! const ROOT_DIR_PATH = nuxt.options.rootDir const UTILS_ALIAS = '@/lib/utils' // Use the same path from the cli for backward compatibility @@ -59,11 +65,15 @@ export default defineNuxtModule({ }) }) - // Install the `@nuxtjs/tailwindcss` module. - await installModule('@nuxtjs/tailwindcss') - - // Installs the `@nuxtjs/color-mode` module. - await installModule('@nuxtjs/color-mode') + const modulesToInstall = ['@nuxtjs/tailwindcss', '@nuxtjs/color-mode'] + for (const module of modulesToInstall) { + if (await findPath(await resolvePath(module))) { + await installModule(module) + } + else if (!suppressMissingModuleWarning) { + logger.warn(`[shadcn-nuxt] \`${module}\` is not installed. To suppress this warning, set \`suppressMissingModuleWarning\` to \`true\` in module options.`) + } + } // Manually scan `componentsDir` for components and register them for auto imports try {