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

feat: add support for using nuxt/ui in pure vue using unplugin #2416

Draft
wants to merge 21 commits into
base: v3
Choose a base branch
from

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Oct 18, 2024

πŸ”— Linked issue

resolves #2129

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This adds support for using Nuxt UI using Vue. It's been built in an abstract way with unplugin so that conceivably this could run for non-vite-based projects.

Note: added fast-deep-equal as an explicit dependency as it was previously an implicit dependency of Nuxt.

πŸ“– Usage

You can test the PR with https://github.com/danielroe/nuxt-ui-vue (using the power of pkg.pr.now), or follow these steps:

  1. Install the Nuxt UI v3 alpha package:
pnpm add https://pkg.pr.new/@nuxt/ui@2416
  1. Add the Nuxt UI Vite plugin in your vite.config.ts{lang="ts-type"}:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { NuxtUIPlugin } from '@nuxt/ui/unplugin'

export default defineConfig({
  plugins: [
    vue(),
    NuxtUIPlugin.vite()
  ],
})
  1. Nuxt UI registers unplugin-auto-import and unplugin-vue-components, which will generate auto-imports.d.ts and components.d.ts type declaration files. You will likely want to gitignore these, and add them to your tsconfig.
{
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "auto-imports.d.ts", "components.d.ts"]
}
# Auto-generated type declarations
auto-imports.d.ts
components.d.ts
  1. Register the Nuxt UI Vue plugin in your app:
import { createApp } from 'vue'
import nuxtUI from '@nuxt/ui/vue-plugin'
import App from './App.vue'

const app = createApp(App)
// ...
app.use(nuxtUI)
app.mount('#app')
  1. Import Tailwind CSS and Nuxt UI in your App.vue or CSS:
<style>
@import "tailwindcss";
@import "@nuxt/ui";
</style>

Warning

If you're using pnpm, ensure that you either set shamefully-hoist=true in your .npmrc file or install tailwindcss@next, vue-router and @unhead/vue directly in your project's root directory.

🚧 TODO

  • remove support for reading app.config.ts in rootDir and support passing config directly via options in unplugin
  • document need to install tailwindcss@alpha, vue-router and @unhead/vue
  • add documentation for how to use in Vue - currently requires 1) adding a plugin to vite config, 2) registering a Vue plugin and 3) updating your .gitignore and tsconfig.app.json
  • remove hard dependency on Nuxt for NuxtLinkProps
  • better type safety for component props
  • investigate if we need to support size prop for @iconify/vue
  • tests to ensure changes to Nuxt UI do not produce regressions for Vue

@danielroe danielroe added enhancement New feature or request v3 #1289 labels Oct 18, 2024
@danielroe danielroe self-assigned this Oct 18, 2024
Copy link

cloudflare-workers-and-pages bot commented Oct 18, 2024

Deploying ui3 with Β Cloudflare Pages Β Cloudflare Pages

Latest commit: d5949e3
Status:Β βœ…Β  Deploy successful!
Preview URL: https://a2e77560.ui-6q2.pages.dev
Branch Preview URL: https://vue.ui-6q2.pages.dev

View logs

Copy link

pkg-pr-new bot commented Oct 18, 2024

pnpm add https://pkg.pr.new/@nuxt/ui@2416

commit: d5949e3

@AaronDewes
Copy link

Wouldn't this also work for pnpm (I'm not using pnpm much and haven't tried)?

public-hoist-pattern[]=tailwindcss
public-hoist-pattern[]=vue-router
public-hoist-pattern[]=@unhead/vue

I think this is a better option, because it does not affect all packages, but also doesn't need users to manually update Tailwind/vue-router/@unhead/vue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v3 #1289
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants