Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module): allow using without recommended modules #1000

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/www/src/content/docs/installation/nuxt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<br>
Expand Down Expand Up @@ -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
}
})
```
Expand Down
22 changes: 16 additions & 6 deletions packages/module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export interface ModuleOptions {
* @default "./components/ui"
*/
componentDir?: string
/**
* Suppress warning about missing modules
* @default false
*/
suppressMissingModuleWarning?: boolean
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -26,8 +31,9 @@ export default defineNuxtModule<ModuleOptions>({
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
Expand Down Expand Up @@ -59,11 +65,15 @@ export default defineNuxtModule<ModuleOptions>({
})
})

// 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 {
Expand Down