//nuxt-config-schemabyTahul

nuxt-config-schema

1
0
1

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 and supports extending layers.

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

Usage

  1. Install nuxt-config-schema as dev dependency:
# npm
npm i -D nuxt-config-schema

# pnpm
pnpm add -D nuxt-config-schema

# yarn
yarn add nuxt-config-schema
  1. Add module to nuxt.config:
export default defineNuxtConfig({
  modules: [
    'nuxt-config-schema'
  ]
})
  1. Create nuxt.schema.ts:
export default defineNuxtConfigSchema({
  appConfig: {
    test2: {
      $default: 'from nuxt.schema'
    }
  },
  /** Config schema for another integration */
  anotherConfig: {
    aTest: '123'
  }
})
  1. Use nuxi dev or nuxi build commands

You can access generated schema (json, markdown and types) from .nuxt/schema/ directory and also schema:resolved(schema) hook from other modules.

Development

  • Run npm run dev:prepare to generate type stubs.
  • Use npm run dev to start playground in development mode.
[beta]v0.13.0