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

refactor: init CLI and @nuxtjs/color-mode module config #886

Closed
wants to merge 2 commits into from
Closed
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
55 changes: 31 additions & 24 deletions apps/www/src/content/docs/installation/nuxt.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,14 @@ If you encounter the error `ERROR: Cannot read properties of undefined (reading
npm install -D typescript
```

### Install TailwindCSS module

```bash
npx nuxi@latest module add @nuxtjs/tailwindcss
```

Alternatively, you can manually add `@nuxtjs/tailwindcss` using your dependency manager

```bash
npm install --save-dev @nuxtjs/tailwindcss
```

and then to the `modules` section of `nuxt.config.{ts,js}`

```ts
export default defineNuxtConfig({
modules: [
'@nuxtjs/tailwindcss'
]
})
```

### Add `Nuxt` module

<br>

<TabsMarkdown>
<TabMarkdown title="shadcn-nuxt">

Install the package below.
Installing the `shadcn-nuxt` module automatically installs and configures `@nuxtjs/tailwindcss` and `@nuxtjs/color-mode` modules.

```bash
npx nuxi@latest module add shadcn-nuxt
Expand Down Expand Up @@ -177,6 +155,35 @@ declare module '@nuxt/schema' {
shadcn?: ShadcnVueOptions;
}
}
```
### Install TailwindCss
```bash
npx nuxi@latest module add @nuxtjs/tailwindcss
```
If not configured automatically in the `nuxt.config.ts` file, configure it as shown below:
```ts
export default defineNuxtConfig({
modules: ['@nuxtjs/tailwindcss'],
})
```
### Install Color Mode
```bash
npx nuxi module add color-mode
```
If not configured automatically in the `nuxt.config.ts` file, configure it as shown below:
```ts
export default defineNuxtConfig({
modules: ['...', '@nuxtjs/color-mode'],
classSuffix: ''
})
```
</TabMarkdown>
Expand All @@ -186,7 +193,7 @@ declare module '@nuxt/schema' {
```ts
export default defineNuxtConfig({
modules: ['@nuxtjs/tailwindcss', 'shadcn-nuxt'],
modules: ['shadcn-nuxt'],
shadcn: {
/**
* Prefix for all the imported component
Expand Down
24 changes: 19 additions & 5 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Command } from 'commander'
import { consola } from 'consola'
import { colors } from 'consola/utils'
import { template } from 'lodash-es'
import { addDependency } from 'nypm'
import { addDependency, addDevDependency } from 'nypm'
import ora from 'ora'
import path from 'pathe'
import prompts from 'prompts'
Expand Down Expand Up @@ -39,6 +39,9 @@ const PROJECT_DEPENDENCIES = {
'tailwind-merge',
'radix-vue',
],
nuxt: [
'shadcn-nuxt',
],
}

const initOptionsSchema = z.object({
Expand Down Expand Up @@ -309,10 +312,21 @@ export async function runInit(cwd: string, config: Config) {
const iconsDep = config.style === 'new-york' ? ['@radix-icons/vue'] : ['lucide-vue-next']
const deps = PROJECT_DEPENDENCIES.base.concat(iconsDep).filter(Boolean)

await addDependency(deps, {
cwd,
silent: true,
})
await Promise.allSettled(
[
config.framework === 'nuxt' && await addDevDependency(
[...PROJECT_DEPENDENCIES.nuxt, ...deps],
{
cwd,
silent: true,
},
),
await addDependency(deps, {
cwd,
silent: true,
}),
],
)

dependenciesSpinner?.succeed()
}
2 changes: 1 addition & 1 deletion packages/module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default defineNuxtModule<ModuleOptions>({
await installModule('@nuxtjs/tailwindcss')

// Installs the `@nuxtjs/color-mode` module.
await installModule('@nuxtjs/color-mode')
await installModule('@nuxtjs/color-mode', { classSuffix: '' })

// Manually scan `componentsDir` for components and register them for auto imports
try {
Expand Down