-
Notifications
You must be signed in to change notification settings - Fork 424
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
Open
Jeanspkdz
wants to merge
4
commits into
pingdotgg:main
Choose a base branch
from
Jeanspkdz:feat/nuxt4-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
724a45d
feat: migrate module to Nuxt 4 and add Tailwind v4 support
Jeanspkdz ca887a3
fix: address review feedback (README, casing, handler init)
Jeanspkdz ea44ba9
refactor: move generated artifacts to Nuxt build dir
Jeanspkdz 12dd75c
fix: resolve UploadThing Vue from module package
Jeanspkdz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,155 +1,136 @@ | ||
| # 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/@uploadthing/nuxt) | ||
| [](https://npm.chart.dev/@uploadthing/nuxt) | ||
| [](https://npmjs.com/package/@uploadthing/nuxt) | ||
| [](https://nuxt.com) | ||
|
|
||
| Nuxt module for getting started with UploadThing in your Nuxt app. | ||
|
|
||
| - [✨ Release Notes](/CHANGELOG.md) | ||
| Nuxt module for UploadThing with type-safe router integration, generated components, and auto-registered helpers. | ||
|
|
||
| ## Quick Setup | ||
| --- | ||
|
|
||
| 1. Add `@uploadthing/nuxt` and `uploadthing` dependencies to your project | ||
| ## Features | ||
|
|
||
| ```bash | ||
| # Using pnpm | ||
| pnpm add -D @uploadthing/nuxt | ||
| pnpm add uploadthing | ||
|
|
||
| # Using yarn | ||
| yarn add --dev @uploadthing/nuxt | ||
| yarn add uploadthing | ||
| - Type-safe UploadThing router integration | ||
| - Auto-generated upload components | ||
| - Auto-imported UploadThing Vue helpers | ||
| - Optional Tailwind styles integration | ||
|
|
||
| # Using npm | ||
| npm install --save-dev @uploadthing/nuxt | ||
| npm install uploadthing | ||
|
|
||
| # Using bun | ||
| bun add -D @uploadthing/nuxt | ||
| bun add uploadthing | ||
| ``` | ||
| --- | ||
|
|
||
| 2. Add `@uploadthing/nuxt` to the `modules` section of `nuxt.config.ts` | ||
| ## Installation | ||
|
|
||
| ```js | ||
| export default defineNuxtConfig({ | ||
| modules: ["@uploadthing/nuxt"], | ||
| }); | ||
| ```bash | ||
| pnpm add @uploadthing/nuxt uploadthing | ||
| ``` | ||
|
|
||
| That's it! You can now use @uploadthing/nuxt in your Nuxt app ✨ | ||
| --- | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ## Usage | ||
| 1) Add the module in `nuxt.config.ts` | ||
|
|
||
| > For full documentation, see the | ||
| > [UploadThing docs](https://docs.uploadthing.com/getting-started/nuxt) | ||
| ```ts | ||
| export default defineNuxtConfig({ | ||
| modules: ['@uploadthing/nuxt'], | ||
|
|
||
| uploadthing: { | ||
| fileRouterPath: '@@/server/uploadthing', | ||
| fileRouterExport: 'fileRouter', | ||
| componentPrefix: 'Uploadthing', | ||
| useTailwindStyles: false, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| 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 | ||
|
|
||
| ```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: | ||
|
|
||
| 1. `tailwindcss` must be installed in your project. | ||
| 2. Import both Tailwind and `@uploadthing/nuxt` styles in your main CSS file (for example `assets/css/main.css`): | ||
|
|
||
| ```css | ||
| @import "tailwindcss"; | ||
| @import '@uploadthing/nuxt' | ||
| ``` | ||
|
|
||
| If `tailwindcss` is missing, the module falls back to UploadThing default CSS. | ||
|
|
||
| # Develop with the playground | ||
| pnpm dev | ||
| --- | ||
|
|
||
| # Run ESLint | ||
| pnpm lint | ||
| ## Module Options | ||
|
|
||
| ```ts | ||
| uploadthing: { | ||
| fileRouterPath: '@@/server/uploadthing', | ||
| fileRouterExport: 'fileRouter', | ||
| componentPrefix: 'Uploadthing', | ||
| useTailwindStyles: false, | ||
| } | ||
| ``` | ||
|
|
||
| <!-- 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 | ||
| - `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 contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README tells users to install
nuxt-uploadthing, butpackage.jsonstill declares"name": "@uploadthing/nuxt"and the changeset also references@uploadthing/nuxt. The badges at the top also link to thenuxt-uploadthingnpm slug, which would 404 unless this package is being renamed (but the package.json has not changed itsnamefield).Prompt To Fix With AI