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(module): add support for vue using unplugin #2416

Merged
merged 54 commits into from
Oct 25, 2024
Merged

feat(module): add support for vue using unplugin #2416

merged 54 commits into from
Oct 25, 2024

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
  • investigate if we need to support size prop for @iconify/vue
  • better type safety for component props
  • tests to ensure changes to Nuxt UI do not produce regressions for Vue
  • remove hard dependency on Nuxt for NuxtLinkProps

@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: 0f99a4c
Status:Β βœ…Β  Deploy successful!
Preview URL: https://a075f778.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: 0f99a4c

@AaronDewes
Copy link
Contributor

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.

@benjamincanac benjamincanac linked an issue Oct 21, 2024 that may be closed by this pull request
@danielroe danielroe marked this pull request as ready for review October 25, 2024 10:15
@benjamincanac benjamincanac merged commit d4a943e into v3 Oct 25, 2024
3 checks passed
@benjamincanac benjamincanac deleted the vue branch October 25, 2024 15:15
@benjamincanac
Copy link
Member

Thanks again @danielroe! ❀️

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.

Vue compatibility
4 participants