-
Notifications
You must be signed in to change notification settings - Fork 444
feat: migrate module to Nuxt 4 and add Tailwind v4 support #1280
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
724a45d
ca887a3
ea44ba9
12dd75c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@uploadthing/nuxt": major | ||
| --- | ||
|
|
||
| Migrate module to Nuxt 4 and add Tailwind v4 support |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| imports.autoImport=false | ||
| typescript.includeWorkspace=true | ||
| experimental.typescriptBundlerResolution=true | ||
| future.typescriptBundlerResolution=true |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,155 +1,135 @@ | ||||||||||
| # Nuxt UploadThing Module | ||||||||||
|
|
||||||||||
| [![npm version][npm-version-src]][npm-version-href] | ||||||||||
| [![npm downloads][npm-downloads-src]][npm-downloads-href] | ||||||||||
| [![License][license-src]][license-href] [![Nuxt][nuxt-src]][nuxt-href] | ||||||||||
| [](https://npmjs.com/package/nuxt-uploadthing) | ||||||||||
| [](https://npm.chart.dev/nuxt-uploadthing) | ||||||||||
| [](https://npmjs.com/package/nuxt-uploadthing) | ||||||||||
| [](https://nuxt.com) | ||||||||||
|
|
||||||||||
| Nuxt module for getting started with UploadThing in your Nuxt app. | ||||||||||
| Nuxt module for UploadThing with type-safe router integration, generated components, and auto-registered helpers. | ||||||||||
|
|
||||||||||
| - [✨ Release Notes](/CHANGELOG.md) | ||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Quick Setup | ||||||||||
| ## Features | ||||||||||
|
|
||||||||||
| 1. Add `@uploadthing/nuxt` and `uploadthing` dependencies to your project | ||||||||||
| - Type-safe UploadThing router integration | ||||||||||
| - Auto-generated upload components | ||||||||||
| - Auto-imported UploadThing Vue helpers | ||||||||||
| - Optional Tailwind styles integration | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| # Using pnpm | ||||||||||
| pnpm add -D @uploadthing/nuxt | ||||||||||
| pnpm add uploadthing | ||||||||||
|
|
||||||||||
| # Using yarn | ||||||||||
| yarn add --dev @uploadthing/nuxt | ||||||||||
| yarn add uploadthing | ||||||||||
| --- | ||||||||||
|
|
||||||||||
| # Using npm | ||||||||||
| npm install --save-dev @uploadthing/nuxt | ||||||||||
| npm install uploadthing | ||||||||||
| ## Installation | ||||||||||
|
|
||||||||||
| # Using bun | ||||||||||
| bun add -D @uploadthing/nuxt | ||||||||||
| bun add uploadthing | ||||||||||
| ```bash | ||||||||||
| pnpm add nuxt-uploadthing uploadthing | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| 2. Add `@uploadthing/nuxt` to the `modules` section of `nuxt.config.ts` | ||||||||||
| --- | ||||||||||
|
|
||||||||||
| ```js | ||||||||||
| export default defineNuxtConfig({ | ||||||||||
| modules: ["@uploadthing/nuxt"], | ||||||||||
| }); | ||||||||||
| ``` | ||||||||||
| ## Quick Start | ||||||||||
|
|
||||||||||
| That's it! You can now use @uploadthing/nuxt in your Nuxt app ✨ | ||||||||||
| 1) Add the module in `nuxt.config.ts` | ||||||||||
|
|
||||||||||
| ## Usage | ||||||||||
|
|
||||||||||
| > For full documentation, see the | ||||||||||
| > [UploadThing docs](https://docs.uploadthing.com/getting-started/nuxt) | ||||||||||
| ```ts | ||||||||||
| export default defineNuxtConfig({ | ||||||||||
| modules: ['nuxt-uploadthing'], | ||||||||||
|
|
||||||||||
| uploadthing: { | ||||||||||
| fileRouterPath: '@@/server/uploadthing', | ||||||||||
| fileRouterExport: 'fileRouter', | ||||||||||
| componentPrefix: 'UploadThing', | ||||||||||
| useTailwindStyles: false, | ||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||
| }, | ||||||||||
| }) | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| 1. Create an upload router in your app: | ||||||||||
| 2) Create your UploadThing router in `server/uploadthing.ts` | ||||||||||
|
|
||||||||||
| ```js | ||||||||||
| // server/uploadthing.ts | ||||||||||
| import { createUploadthing, UTFiles } from "uploadthing/h3"; | ||||||||||
| import type { FileRouter } from "uploadthing/h3"; | ||||||||||
| ```ts | ||||||||||
| import { createUploadthing, type FileRouter } from 'uploadthing/h3' | ||||||||||
|
|
||||||||||
| const f = createUploadthing(); | ||||||||||
| const f = createUploadthing() | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * This is your Uploadthing file router. For more information: | ||||||||||
| * @see https://docs.uploadthing.com/api-reference/server#file-routes | ||||||||||
| */ | ||||||||||
| export const uploadRouter = { | ||||||||||
| videoAndImage: f({ | ||||||||||
| image: { | ||||||||||
| maxFileSize: "4MB", | ||||||||||
| maxFileCount: 4, | ||||||||||
| acl: "public-read", | ||||||||||
| }, | ||||||||||
| video: { | ||||||||||
| maxFileSize: "16MB", | ||||||||||
| }, | ||||||||||
| export const fileRouter = { | ||||||||||
| imageUploader: f({ | ||||||||||
| image: { maxFileSize: '4MB', maxFileCount: 1 }, | ||||||||||
| }) | ||||||||||
| .middleware(({ event, files }) => { | ||||||||||
| // ^? H3Event | ||||||||||
|
|
||||||||||
| // Return some metadata to be stored with the file | ||||||||||
| return { foo: "bar" as const }; | ||||||||||
| .middleware(async () => { | ||||||||||
| return { userId: 'demo-user' } | ||||||||||
| }) | ||||||||||
| .onUploadComplete(({ file, metadata }) => { | ||||||||||
| // ^? { foo: "bar" } | ||||||||||
| console.log("upload completed", file); | ||||||||||
| .onUploadComplete(async ({ metadata, file }) => { | ||||||||||
| return { | ||||||||||
| uploadedBy: metadata.userId, | ||||||||||
| url: file.ufsUrl, | ||||||||||
| } | ||||||||||
| }), | ||||||||||
| } satisfies FileRouter; | ||||||||||
|
|
||||||||||
| export type UploadRouter = typeof uploadRouter; | ||||||||||
| } satisfies FileRouter | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| 2. Mount a component in your app and start uploading files: | ||||||||||
| 3) Use generated components anywhere in your app | ||||||||||
|
|
||||||||||
|
Comment on lines
70
to
72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The README tells users to install
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/nuxt/README.md
Line: 69-71
Comment:
**Wrong package name in install instructions**
The README tells users to install `nuxt-uploadthing`, but `package.json` still declares `"name": "@uploadthing/nuxt"` and the changeset also references `@uploadthing/nuxt`. The badges at the top also link to the `nuxt-uploadthing` npm slug, which would 404 unless this package is being renamed (but the package.json has not changed its `name` field).
```suggestion
pnpm add @uploadthing/nuxt uploadthing
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||
| ```vue | ||||||||||
| <script setup lang="ts"> | ||||||||||
| const alert = (msg: string) => { | ||||||||||
| window.alert(msg); | ||||||||||
| }; | ||||||||||
| </script> | ||||||||||
|
|
||||||||||
| <template> | ||||||||||
| <div>Playground</div> | ||||||||||
| <UploadButton | ||||||||||
| :config="{ | ||||||||||
| endpoint: 'videoAndImage', | ||||||||||
| onClientUploadComplete: (res) => { | ||||||||||
| console.log(`onClientUploadComplete`, res); | ||||||||||
| alert('Upload Completed'); | ||||||||||
| }, | ||||||||||
| onUploadBegin: () => { | ||||||||||
| console.log(`onUploadBegin`); | ||||||||||
| }, | ||||||||||
| }" | ||||||||||
| /> | ||||||||||
|
|
||||||||||
| <UploadDropzone | ||||||||||
| <UploadThingUploadButton | ||||||||||
| :config="{ | ||||||||||
| endpoint: 'videoAndImage', | ||||||||||
| onClientUploadComplete: (res) => { | ||||||||||
| console.log(`onClientUploadComplete`, res); | ||||||||||
| alert('Upload Completed'); | ||||||||||
| }, | ||||||||||
| onUploadBegin: () => { | ||||||||||
| console.log(`onUploadBegin`); | ||||||||||
| }, | ||||||||||
| endpoint: 'imageUploader', | ||||||||||
| onClientUploadComplete: (res) => console.log(res), | ||||||||||
| onUploadError: (error) => console.error(error), | ||||||||||
| }" | ||||||||||
| /> | ||||||||||
| </template> | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Wow, that was easy! | ||||||||||
|
|
||||||||||
| ## Development | ||||||||||
|
|
||||||||||
| From workspace root: | ||||||||||
| ## Tailwind Styles | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| # Install dependencies | ||||||||||
| pnpm install | ||||||||||
| To use UploadThing Tailwind styles, enable: | ||||||||||
|
|
||||||||||
| ```ts | ||||||||||
| uploadthing: { | ||||||||||
| useTailwindStyles: true, | ||||||||||
| } | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Requirements: | ||||||||||
|
|
||||||||||
| # Develop with the playground | ||||||||||
| pnpm dev | ||||||||||
| 1. `tailwindcss` must be installed in your project. | ||||||||||
| 2. Import both Tailwind and `nuxt-uploadthing` styles in your main CSS file (for example `assets/css/main.css`): | ||||||||||
|
|
||||||||||
| # Run ESLint | ||||||||||
| pnpm lint | ||||||||||
| ```css | ||||||||||
| @import "tailwindcss"; | ||||||||||
| @import '@uploadthing/nuxt' | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| <!-- Badges --> | ||||||||||
|
|
||||||||||
| [npm-version-src]: | ||||||||||
| https://img.shields.io/npm/v/@uploadthing/nuxt/latest.svg?style=flat&colorA=18181B&colorB=28CF8D | ||||||||||
| [npm-version-href]: https://npmjs.com/package/@uploadthing/nuxt | ||||||||||
| [npm-downloads-src]: | ||||||||||
| https://img.shields.io/npm/dm/@uploadthing/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D | ||||||||||
| [npm-downloads-href]: https://npmjs.com/package/@uploadthing/nuxt | ||||||||||
| [license-src]: | ||||||||||
| https://img.shields.io/npm/l/@uploadthing/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D | ||||||||||
| [license-href]: https://npmjs.com/package/@uploadthing/nuxt | ||||||||||
| [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js | ||||||||||
| [nuxt-href]: https://nuxt.com | ||||||||||
| If `tailwindcss` is missing, the module falls back to UploadThing default CSS. | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Module Options | ||||||||||
|
|
||||||||||
| ```ts | ||||||||||
| uploadthing: { | ||||||||||
| fileRouterPath: '@@/server/uploadthing', | ||||||||||
| fileRouterExport: 'fileRouter', | ||||||||||
| componentPrefix: 'Uploadthing', | ||||||||||
| useTailwindStyles: false, | ||||||||||
| } | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| - `fileRouterPath`: Path to your UploadThing router file. | ||||||||||
| - `fileRouterExport`: Export name of the router in that file. | ||||||||||
| - `componentPrefix`: Prefix for generated components (`<prefix>UploadButton`, `<prefix>UploadDropzone`). | ||||||||||
| - `useTailwindStyles`: Enable UploadThing Tailwind styles integration. | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Auto-Imports | ||||||||||
|
|
||||||||||
| The module auto-imports these helpers: | ||||||||||
|
|
||||||||||
| - `useUploadThing` | ||||||||||
| - `createUpload` | ||||||||||
| - `routeRegistry` | ||||||||||
| - `uploadFiles` | ||||||||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.