# nuxt-config-schema

> This is a proof of concept module for a feature in Nuxt 3 that automatically infers and generates schema based on user provided configuration from several sources using [unjs/untyped](https://github.com/unjs/untyped) and supports extending layers.

Latest version **0.4.7** (published 2024-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install nuxt-config-schema
pnpm add nuxt-config-schema
yarn add nuxt-config-schema
bun add nuxt-config-schema
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.7 |
| Published | 2024-11-05 |
| First published | 2022-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | pi0, danielroe |

## Links

- npm: https://www.npmjs.com/package/nuxt-config-schema
- npm.io page: https://npm.io/package/nuxt-config-schema

## Dependencies (5)

- [defu](https://npm.io/package/defu.md) ^6.1.4
- [jiti](https://npm.io/package/jiti.md) ^2.4.0
- [pathe](https://npm.io/package/pathe.md) ^1.1.2
- [untyped](https://npm.io/package/untyped.md) ^1.5.1
- [@nuxt/kit](https://npm.io/package/@nuxt/kit.md) ^3.14.0

## Recent versions

- 0.4.7 (latest) — 2024-11-05
- 0.4.6 — 2023-04-21
- 0.4.5 — 2023-02-28
- 0.4.4 — 2023-01-24
- 0.4.3 — 2023-01-23
- 0.4.2 — 2023-01-13
- 0.4.1 — 2023-01-13
- 0.4.0 — 2023-01-03
- 0.3.8 — 2023-01-03
- 0.3.7 — 2022-12-21
- 0.3.6 — 2022-12-14
- 0.3.5 — 2022-12-13
- 0.3.4 — 2022-11-29
- 0.3.3 — 2022-11-29
- 0.3.2 — 2022-11-29
- … 5 more at https://npm.io/package/nuxt-config-schema/versions

## README

# Nuxt Config Schema

This is a proof of concept module for a feature in Nuxt 3 that automatically infers and generates schema based on user provided configuration from several sources using [unjs/untyped](https://github.com/unjs/untyped) and supports extending layers.

Schema can be defined in `nuxt.schema.ts` or `$schema` field in `nuxt.config.ts`.

Read the [proposal for Nuxt 3](https://github.com/nuxt/nuxt/issues/15592)

This experiment is landed to Nuxt 3 core since 3.1.0 (https://github.com/nuxt/nuxt/pull/18410)

## Usage

1. Install `nuxt-config-schema` as dev dependency:

```sh
# npm
npm i -D nuxt-config-schema

# pnpm
pnpm add -D nuxt-config-schema

# yarn
yarn add nuxt-config-schema
```

2. Add module to `nuxt.config`:

```js
export default defineNuxtConfig({
  modules: ['nuxt-config-schema'],
})
```

3. Create `nuxt.schema.ts`:

```ts
export default defineNuxtConfigSchema({
  appConfig: {
    test2: {
      $default: 'from nuxt.schema',
    },
  },
  /** Config schema for another integration */
  anotherConfig: {
    aTest: '123',
  },
})
```

4. Use `nuxi dev` or `nuxi build` commands

You can access generated schema (json, markdown and types) from `.nuxt/schema/` directory and also hooks below:

- `schema:extend(schemaDefs)`: Extend schema defenitions (first call after `modules:done` hook)
- `schema:resolved(schema)`: Extend resolved schema after merging (first call after `modules:done` hook)
- `schema:beforeWrite(schema)`: Extend resolved schema just before writing to filesystem (called after `build:done` hook)
- `schema:written`: Hook will be called when schema has been written and updated to filesystem

## Development

- Run `npm run dev:prepare` to generate type stubs.
- Use `npm run dev` to start [playground](./playground) in development mode.

---
_Source: https://npm.io/package/nuxt-config-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
