2.2.0 • Published 4 months ago

nuxt-prepare v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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
  • 🦾 Better DX with defineNuxtPrepareHandler

Setup

!TIP(https://nuxt-prepare.byjohann.dev)

npx nuxi@latest module add prepare

Basic Usage

!TIP(https://nuxt-prepare.byjohann.dev)

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

2.2.0

4 months ago

2.1.1

4 months ago

2.1.0

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.1.0

11 months ago

1.0.0

11 months ago

0.3.0

11 months ago

0.2.2

1 year ago

0.2.1

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago