nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.28k stars 516 forks source link

ignore is not working #2863

Closed MickL closed 2 weeks ago

MickL commented 2 weeks ago

Environment

Nitro: 2.10.4 Bun: 1.1.34 Node: 22.11.0

Reproduction

Describe the bug

In Nuxt we can set ignore array within nuxt.config.ts. In Nitro there seems to be the same option but it does nothing:

export default defineNitroConfig({
  ignore: ['/dev-only'],
});

Additional context

I want to disable some routes in product that are only for development.

Logs

No response

pi0 commented 2 weeks ago

ignore is an array for glob patterns. Nitro uses glob option for ignore scan patterns (plugins, routes, etc) + static assets.

This works on sandbox:

//https://nitro.unjs.io/config
export default defineNitroConfig({
  ignore: ['routes/dev-only/**'],
  compatibilityDate: '2024-11-08'
});
pi0 commented 2 weeks ago

PS: Nitro 2.10 supports .dev prefix in files to automatically exclude them from production :)

MickL commented 2 weeks ago

PS: Nitro 2.10 supports .dev prefix in files to automatically exclude them from production :)

Thats amazing! Does it work also in Nuxt with pages/components/assets or is it Nitro exlusive?

Also I wonder if this works with a folder?

/routes/temp.dev/tester.ts
pi0 commented 2 weeks ago

The suffix is supported file-level -- but you can programmatically also add conditions flag to nitro.options.handlers

Nuxt has <DevOnly> i can't recall TBH but i guess it did add support for .dev for components, if not maybe worth making a proposal for Nuxt.

Shalll we close this issue? (please feel free to use discussions or discord always!)

MickL commented 2 weeks ago
'routes/dev-only/**'

Did the trick, thanks! The ignore option should be documented :)