Skip to content

feat: add @netlify/nuxt Nuxt module #344

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
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

serhalp
Copy link
Member

@serhalp serhalp commented Jul 11, 2025

(collab with @danielroe!)

This is basically the same thing as @netlify/vite-plugin, but as a Nuxt module.

Nuxt developers expect to extend Nuxt with Nuxt modules, not Vite plugins.

This is effectively the same thing as @netlify/vite-plugin (which is a thin wrapper over @netlify/dev), but wrapped as a Nuxt module so that it can use Nitro hooks to register the server start/stop and hook up its middleware to the Nitro server.

Because Nuxt's Vite and Nitro servers are separate and Nitro runs first anyway, it isn't possible to simply use a Vite plugin for this. (However, there is work underway in Nitro that is coming very very soon that would make this possible in Nitro v3!)


Co-authored-by: Daniel Roe [email protected]

@serhalp serhalp force-pushed the serhalp/frb-1847-support-netlifyvite-plugin-in-nuxt branch from 438bf97 to 46548e2 Compare July 11, 2025 22:11
@serhalp serhalp force-pushed the serhalp/frb-1847-support-netlifyvite-plugin-in-nuxt branch from b4cde10 to e89c2d8 Compare July 11, 2025 22:36
@@ -0,0 +1,18 @@
// @ts-check
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whole module was scaffolded by npm create nuxt -- -t module

"description": "Nuxt module providing local emulation of the Netlify environment",
"type": "module",
"engines": {
"node": "^20.6.1 || >=22"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same range as our other new packages

Comment on lines +35 to +36
"//": "Workaround to run this package's eslint in CI",
"test:ci": "npm run lint && npm run test:types && npm run test",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current CI workflows make very specific assumptions about all packages, so I just squeezed this into test:ci

"@nuxt/schema": "^3.17.6",
"@nuxt/test-utils": "^3.19.2",
"@types/node": "latest",
"changelogen": "^0.6.2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"changelogen": "^0.6.2",

"@nuxt/module-builder": "^1.0.1",
"@nuxt/schema": "^3.17.6",
"@nuxt/test-utils": "^3.19.2",
"@types/node": "latest",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting choice from the scaffold... we should update this

@@ -0,0 +1,110 @@
import process from 'node:process'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is very similar to the vite plugin implementation. it was copied and adjusted to use nitro hooks.

import * as vite from 'vite'

import { createLoggerFromViteLogger } from './lib/logger.js'
import { fromWebResponse } from './lib/reqres.js'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to @netlify/dev-utils so I could use it in the nuxt module too

@serhalp
Copy link
Member Author

serhalp commented Jul 12, 2025

I imagine the failing node 20.6.1 test is because nuxt (3) requires 20.9.0? I'll take a look on Monday

@serhalp serhalp marked this pull request as ready for review July 12, 2025 00:39
@serhalp serhalp requested review from a team as code owners July 12, 2025 00:39

export type NetlifyModuleOptions = Features

const createPrefixedLogger = (prefix: string, logger: Logger) => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could move somewhere centralised at some point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, the vite plugin uses the passed vite logger which is configured with a similar-ish thing in a more first-class way. This was my half-assed equivalent with our own console-based logger, so I don't see us reusing it any time soon.

@pi0
Copy link

pi0 commented Jul 12, 2025

@serhalp @eduardoboucas sent a DM.

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.

3 participants