Skip to content

feat(core, vite): interoperability between nitro modules and vite plugins (poc)#3712

Merged
pi0 merged 4 commits intomainfrom
feat/nitro-vite-plugin-interop
Oct 31, 2025
Merged

feat(core, vite): interoperability between nitro modules and vite plugins (poc)#3712
pi0 merged 4 commits intomainfrom
feat/nitro-vite-plugin-interop

Conversation

@pi0
Copy link
Member

@pi0 pi0 commented Oct 31, 2025

Note

There is still an ongoing discussion to decide on best namespace. This PR is initial step and we might extend it to support a new nested namespace for extension. In the meantime, it is a safe first step to try and adopt the idea. (RFC: #3680)

This PR adds a new module format to the core: { nitro: { setup } }.

This allows developers to make vite plugins with an additional/optional nitro: {} hook.

When used together with nitro/vite plugin, these plugins will be detected by Nitro and used as modules.

Example: plugin:

export function extension(options): Plugin {
   return {
      name: "my-addon"
      // Normal vite plugin hooks
      resolveId(id) {},
      // Nitro hooks
      nitro: { setup(nitro) { } }
   }
}

Usage in vite.config: (vite CLI)

import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { extension } from 'integration/vite'

export default defineConfig({
  plugins: [nitro(), extension()],
})

Usage in nitro.config (nitro CLI)

import { defineNitroConfig } from 'nitro/vite'
import { extension } from 'integration/vite'

export default defineNitroConfig({
  modules: [extension]
})

@vercel
Copy link

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nitro.build Ready Ready Preview Comment Oct 31, 2025 7:09pm

@pi0 pi0 requested a review from a team October 31, 2025 19:04
@pi0 pi0 changed the title feat(vite): interoperability between nitro modules and vite plugins feat(vite): interoperability between nitro modules and vite plugins (poc) Oct 31, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 31, 2025

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@3712

commit: 182a0f6

@pi0 pi0 merged commit 219987c into main Oct 31, 2025
5 checks passed
@pi0 pi0 deleted the feat/nitro-vite-plugin-interop branch October 31, 2025 19:10
pi0 added a commit that referenced this pull request Oct 31, 2025
@pi0 pi0 changed the title feat(vite): interoperability between nitro modules and vite plugins (poc) feat(core, vite): interoperability between nitro modules and vite plugins (poc) Nov 1, 2025
productdevbook added a commit to productdevbook/nitro-graphql that referenced this pull request Nov 4, 2025
This implements the new Nitro v3 pattern where Vite plugins can include
a `nitro:` key to automatically register Nitro modules, eliminating the
need for separate configuration.

**Changes:**
- Extract shared setup logic into `src/setup.ts` for reuse
- Update `src/vite.ts` to include `nitro: { setup() }` hook
- Accept `NitroGraphQLOptions` in the Vite plugin function
- Update `src/index.ts` to use the extracted setup function
- Update Vite playground to demonstrate the new single-import pattern

**Benefits:**
- Single import: users only need `graphql()` from `nitro-graphql/vite`
- Plugin order independence (as per Nitro v3 changes)
- Better DX and consistency with modern Nitro v3 patterns
- Full backward compatibility with existing `modules: ['nitro-graphql']` approach

**Usage:**
```typescript
// New pattern (recommended)
import { graphql } from 'nitro-graphql/vite'
import { nitro } from 'nitro/vite'

export default defineConfig({
  plugins: [
    graphql({ framework: 'graphql-yoga' }),
    nitro()
  ]
})
```

**Related:**
- Nitro PR: nitrojs/nitro#3712

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
productdevbook added a commit to productdevbook/nitro-graphql that referenced this pull request Nov 4, 2025
* feat: add Nitro v3 Vite plugin integration with nitro: hook

This implements the new Nitro v3 pattern where Vite plugins can include
a `nitro:` key to automatically register Nitro modules, eliminating the
need for separate configuration.

**Changes:**
- Extract shared setup logic into `src/setup.ts` for reuse
- Update `src/vite.ts` to include `nitro: { setup() }` hook
- Accept `NitroGraphQLOptions` in the Vite plugin function
- Update `src/index.ts` to use the extracted setup function
- Update Vite playground to demonstrate the new single-import pattern

**Benefits:**
- Single import: users only need `graphql()` from `nitro-graphql/vite`
- Plugin order independence (as per Nitro v3 changes)
- Better DX and consistency with modern Nitro v3 patterns
- Full backward compatibility with existing `modules: ['nitro-graphql']` approach

**Usage:**
```typescript
// New pattern (recommended)
import { graphql } from 'nitro-graphql/vite'
import { nitro } from 'nitro/vite'

export default defineConfig({
  plugins: [
    graphql({ framework: 'graphql-yoga' }),
    nitro()
  ]
})
```

**Related:**
- Nitro PR: nitrojs/nitro#3712

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore: bump version to 2.0.0-beta.13

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant