GitXplorerGitXplorer
j

nuxt-prepare

public
102 stars
4 forks
0 issues

Commits

List of commits on branch main.
Unverified
19ad7a269be67464ebf594a403223eac43de4755

build: exclude `dist` from typechecl

jjohannschopplich committed 5 days ago
Unverified
29e973c95bb9340f0df032febd3698c1324471af

build: update to latest nuxt/module-builder + drop cjs support

jjohannschopplich committed 5 days ago
Unverified
ad156a904df230fd348a3fb97f50c653cd0d6697

docs: remove Plausible tracking

jjohannschopplich committed 20 days ago
Unverified
fd382c313943d50522d067e6527749805f5378a3

chore: lint with `@antfu/eslint-config`

jjohannschopplich committed 2 months ago
Unverified
af6b6e355de9249c6520809ecd964404b4216c72

chore: release v2.3.0

jjohannschopplich committed 2 months ago
Unverified
abb5a0f047155380a14a7b961b04c47fc67a5d8c

feat: Resolve `#nuxt-prepare` in Nitro server routes (fixes #18)

jjohannschopplich committed 2 months ago

README

The README file for this repository.

Nuxt Prepare module

Nuxt Prepare

Nuxt module to run async initialization steps at build-time.

Features

  • 🦦 Zero-Config
  • 🦎 Run sync or async operations when Nuxt builds your app
  • ✂️ Conditionally overwrite runtime config or app config values
  • 🍡 Run scripts in series or parallel
  • 🥢 Ready for Nitro server routes
  • 🦾 Better DX with defineNuxtPrepareHandler

Setup

[!TIP] 📖 Read the documentation

npx nuxi@latest module add prepare

Basic Usage

[!TIP] 📖 Read the documentation

Add the nuxt-prepare module to your nuxt.config.ts:

// `nuxt.config.ts`
export default defineNuxtConfig({
  modules: ['nuxt-prepare']
})

By default, Nuxt Prepare will look for a server.prepare.ts file in your project root. To run synchronous or asynchronous code when Nuxt builds your app, define a handler in your project root and export a default function:

// `server.prepare.ts`
import { defineNuxtPrepareHandler } from 'nuxt-prepare/config'

export default defineNuxtPrepareHandler(async () => {
  // Do some async magic here, e.g. fetch data from an API

  return {
    // Overwrite the runtime config variable `foo`
    runtimeConfig: {
      public: {
        foo: 'Overwritten by "server.prepare" script'
      }
    },

    // Pass custom state to Nuxt and import it
    // anywhere from `#nuxt-prepare`
    state: {
      foo: 'bar'
    }
  }
})

[!TIP] You can run as many prepare scripts as you want – add them to the prepare.scripts module configuration.

💻 Development

  1. Clone this repository
  2. Enable Corepack using corepack enable
  3. Install dependencies using pnpm install
  4. Run pnpm run dev:prepare
  5. Start development server using pnpm run dev

Credits

License

MIT License © 2023-PRESENT Johann Schopplich