Skip to content

Commit 7586b5e

Browse files
authored
feat: Nuxt module (#197)
* feat: add nuxt module * chore: bundle module * chore: update package, readme * docs: update nuxt installation with new module * docs: remove Ui prefix to prevent confusion * chore: cleanup
1 parent caa8994 commit 7586b5e

File tree

24 files changed

+5961
-213
lines changed

24 files changed

+5961
-213
lines changed

apps/www/src/content/docs/installation/nuxt.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,28 @@ npm install -D typescript
2626
npm install -D @nuxtjs/tailwindcss
2727
```
2828

29-
### Configure `nuxt.config.ts`
30-
31-
<Callout class="mt-4">
29+
### Install `shadcn-nuxt` module (New ✨)
3230

33-
**Tip:** It's better to use Nuxt `components:dirs` hook to extend auto-import components directories.
31+
```bash
32+
npm install -D shadcn-nuxt
33+
```
3434

35-
If you use `components` key in `nuxt.config.ts` default config will disposed
3635

37-
</Callout>
36+
### Configure `nuxt.config.ts`
3837

3938
```ts
4039
export default defineNuxtConfig({
41-
modules: ['@nuxtjs/tailwindcss'],
42-
hooks: {
43-
'components:dirs': (dirs) => {
44-
dirs.unshift({
45-
path: '~/components/ui',
46-
// this is required else Nuxt will autoImport `.ts` file
47-
extensions: ['.vue'],
48-
// prefix for your components, eg: UiButton
49-
prefix: 'Ui',
50-
// prevent adding another prefix component by it's path.
51-
pathPrefix: false
52-
})
53-
}
40+
modules: ['@nuxtjs/tailwindcss', 'shadcn-nuxt'],
41+
shadcn: {
42+
/**
43+
* Prefix for all the imported component
44+
*/
45+
prefix: '',
46+
/**
47+
* Directory that the component lives in.
48+
* @default "./components/ui"
49+
*/
50+
componentDir: './components/ui'
5451
}
5552
})
5653
```
@@ -133,7 +130,7 @@ The command above will add the `Button` component to your project. Nuxt autoImpo
133130
```vue {3}
134131
<template>
135132
<div>
136-
<UiButton>Click me</UiButton>
133+
<Button>Click me</Button>
137134
</div>
138135
</template>
139136
```

packages/module/.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Logs
5+
*.log*
6+
7+
# Temp directories
8+
.temp
9+
.tmp
10+
.cache
11+
12+
# Yarn
13+
**/.yarn/cache
14+
**/.yarn/*state*
15+
16+
# Generated dirs
17+
dist
18+
19+
# Nuxt
20+
.nuxt
21+
.output
22+
.data
23+
.vercel_build_output
24+
.build-*
25+
.netlify
26+
27+
# Env
28+
.env
29+
30+
# Testing
31+
reports
32+
coverage
33+
*.lcov
34+
.nyc_output
35+
36+
# VSCode
37+
.vscode/*
38+
!.vscode/settings.json
39+
!.vscode/tasks.json
40+
!.vscode/launch.json
41+
!.vscode/extensions.json
42+
!.vscode/*.code-snippets
43+
44+
# Intellij idea
45+
*.iml
46+
.idea
47+
48+
# OSX
49+
.DS_Store
50+
.AppleDouble
51+
.LSOverride
52+
.AppleDB
53+
.AppleDesktop
54+
Network Trash Folder
55+
Temporary Items
56+
.apdisk

packages/module/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

packages/module/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<!--
2+
Get your module up and running quickly.
3+
4+
Find and replace all on all files (CMD+SHIFT+F):
5+
- Name: Shadcn Nuxt
6+
- Package name: shadcn-nuxt
7+
- Description: My new Nuxt module
8+
-->
9+
10+
# Shadcn Nuxt
11+
12+
[![npm version][npm-version-src]][npm-version-href]
13+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
14+
[![License][license-src]][license-href]
15+
[![Nuxt][nuxt-src]][nuxt-href]
16+
17+
Shadcn Vue module for Nuxt.
18+
19+
- [&nbsp;Release Notes](/CHANGELOG.md)
20+
<!-- - [🏀 Online playground](https://stackblitz.com/github/radix-vue/shadcn-vue?file=playground%2Fapp.vue) -->
21+
- [📖 &nbsp;Documentation](https://www.shadcn-vue.com/docs/installation/nuxt.html)
22+
23+
## Features
24+
25+
<!-- Highlight some of the features your module provide here -->
26+
- ⛰ Auto-import correct and relevant components
27+
- more to come...
28+
29+
## Quick Setup
30+
31+
1. Add `shadcn-nuxt` dependency to your project
32+
33+
```bash
34+
# Using pnpm
35+
pnpm add -D shadcn-nuxt
36+
37+
# Using yarn
38+
yarn add --dev shadcn-nuxt
39+
40+
# Using npm
41+
npm install --save-dev shadcn-nuxt
42+
```
43+
44+
2. Add `shadcn-nuxt` to the `modules` section of `nuxt.config.ts`
45+
46+
```js
47+
export default defineNuxtConfig({
48+
modules: [
49+
'shadcn-nuxt'
50+
],
51+
shadcn: {
52+
/**
53+
* Prefix for all the imported component
54+
*/
55+
prefix: '',
56+
/**
57+
* Directory that the component lives in.
58+
* @default "./components/ui"
59+
*/
60+
componentDir: './components/ui'
61+
}
62+
})
63+
```
64+
65+
That's it! You can now use Shadcn Nuxt in your Nuxt app ✨
66+
67+
## Development
68+
69+
```bash
70+
# Install dependencies
71+
npm install
72+
73+
# Generate type stubs
74+
npm run dev:prepare
75+
76+
# Develop with the playground
77+
npm run dev
78+
79+
# Build the playground
80+
npm run dev:build
81+
82+
# Run ESLint
83+
npm run lint
84+
85+
# Run Vitest
86+
npm run test
87+
npm run test:watch
88+
89+
# Release new version
90+
npm run release
91+
```
92+
93+
<!-- Badges -->
94+
[npm-version-src]: https://img.shields.io/npm/v/shadcn-nuxt/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
95+
[npm-version-href]: https://npmjs.com/package/shadcn-nuxt
96+
97+
[npm-downloads-src]: https://img.shields.io/npm/dm/shadcn-nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
98+
[npm-downloads-href]: https://npmjs.com/package/shadcn-nuxt
99+
100+
[license-src]: https://img.shields.io/npm/l/shadcn-nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
101+
[license-href]: https://npmjs.com/package/shadcn-nuxt
102+
103+
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
104+
[nuxt-href]: https://nuxt.com

packages/module/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "shadcn-nuxt",
3+
"type": "module",
4+
"version": "0.1.0",
5+
"description": "Add shadcn-vue module to Nuxt",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"license": "MIT",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/radix-vue/shadcn-vue.git",
13+
"directory": "packages/module"
14+
},
15+
"exports": {
16+
".": {
17+
"types": "./dist/types.d.ts",
18+
"import": "./dist/module.mjs",
19+
"require": "./dist/module.cjs"
20+
}
21+
},
22+
"main": "./dist/module.cjs",
23+
"types": "./dist/types.d.ts",
24+
"files": [
25+
"dist"
26+
],
27+
"scripts": {
28+
"prepack": "nuxt-module-build build",
29+
"dev": "nuxi dev playground",
30+
"dev:build": "nuxi build playground",
31+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
32+
"lint": "eslint .",
33+
"test": "vitest run",
34+
"test:watch": "vitest watch",
35+
"release": "pnpm run prepack && pnpm publish && git push --follow-tags"
36+
},
37+
"dependencies": {
38+
"@nuxt/kit": "^3.8.2",
39+
"ts-morph": "^19.0.0"
40+
},
41+
"devDependencies": {
42+
"@nuxt/devtools": "latest",
43+
"@nuxt/eslint-config": "^0.2.0",
44+
"@nuxt/module-builder": "^0.5.4",
45+
"@nuxt/schema": "^3.8.2",
46+
"@nuxt/test-utils": "^3.8.1",
47+
"@types/node": "^20.9.3",
48+
"nuxt": "^3.8.2",
49+
"vitest": "^0.33.0"
50+
}
51+
}

packages/module/playground/app.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup>
2+
</script>
3+
4+
<template>
5+
<div>
6+
<UiButton :variant="'destructive'">
7+
hi
8+
</UiButton>
9+
Nuxt module playground!
10+
</div>
11+
</template>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"style": "default",
3+
"typescript": true,
4+
"tailwind": {
5+
"config": "tailwind.config.js",
6+
"css": "assets/css/tailwind.css",
7+
"baseColor": "slate",
8+
"cssVariables": true
9+
},
10+
"framework": "nuxt",
11+
"aliases": {
12+
"components": "@/components",
13+
"utils": "@/lib/utils"
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup lang="ts">
2+
import { buttonVariants } from '.'
3+
import { cn } from '@/lib/utils'
4+
5+
interface Props {
6+
variant?: NonNullable<Parameters<typeof buttonVariants>[0]>['variant']
7+
size?: NonNullable<Parameters<typeof buttonVariants>[0]>['size']
8+
as?: string
9+
}
10+
11+
withDefaults(defineProps<Props>(), {
12+
as: 'button',
13+
})
14+
</script>
15+
16+
<template>
17+
<component
18+
:is="as"
19+
:class="cn(buttonVariants({ variant, size }), $attrs.class ?? '')"
20+
>
21+
<slot />
22+
</component>
23+
</template>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { cva } from 'class-variance-authority'
2+
3+
export { default as Button } from './Button.vue'
4+
5+
export const buttonVariants = cva(
6+
'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
7+
{
8+
variants: {
9+
variant: {
10+
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
11+
destructive:
12+
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
13+
outline:
14+
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
15+
secondary:
16+
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
17+
ghost: 'hover:bg-accent hover:text-accent-foreground',
18+
link: 'text-primary underline-offset-4 hover:underline',
19+
},
20+
size: {
21+
default: 'h-10 px-4 py-2',
22+
sm: 'h-9 rounded-md px-3',
23+
lg: 'h-11 rounded-md px-8',
24+
icon: 'h-10 w-10',
25+
},
26+
},
27+
defaultVariants: {
28+
variant: 'default',
29+
size: 'default',
30+
},
31+
},
32+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup lang="ts">
2+
import { DropdownMenuRoot, type DropdownMenuRootEmits, type DropdownMenuRootProps, useEmitAsProps, useForwardPropsEmits } from 'radix-vue'
3+
4+
const props = defineProps<DropdownMenuRootProps>()
5+
const emits = defineEmits<DropdownMenuRootEmits>()
6+
7+
const forwarded = useForwardPropsEmits(props, emits)
8+
</script>
9+
10+
<template>
11+
<DropdownMenuRoot v-bind="forwarded">
12+
<slot />
13+
</DropdownMenuRoot>
14+
</template>

0 commit comments

Comments
 (0)