Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johannschopplich/nuxt-prepare
π¦ Build actions for Nuxt
https://github.com/johannschopplich/nuxt-prepare
nuxt nuxt-assets nuxt-module
Last synced: 5 days ago
JSON representation
π¦ Build actions for Nuxt
- Host: GitHub
- URL: https://github.com/johannschopplich/nuxt-prepare
- Owner: johannschopplich
- License: mit
- Created: 2023-08-16T18:45:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-27T08:13:15.000Z (29 days ago)
- Last Synced: 2024-12-16T18:52:21.784Z (9 days ago)
- Topics: nuxt, nuxt-assets, nuxt-module
- Language: TypeScript
- Homepage: https://nuxt-prepare.byjohann.dev
- Size: 2.96 MB
- Stars: 101
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[![Nuxt Prepare module](./docs/public/og.jpg)](https://nuxt-prepare.byjohann.dev)
# Nuxt Prepare
[Nuxt](https://nuxt.com) module to run async initialization steps at build-time.
- [β¨ Β Release Notes](https://github.com/johannschopplich/nuxt-prepare/releases)
- [π Β Read the documentation](https://nuxt-prepare.byjohann.dev)## 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](https://nitro.build) server routes
- π¦Ύ Better DX with [`defineNuxtPrepareHandler`](https://nuxt-prepare.byjohann.dev/api/define-nuxt-prepare-handler)## Setup
> [!TIP]
> [π Read the documentation](https://nuxt-prepare.byjohann.dev)```bash
npx nuxi@latest module add prepare
```## Basic Usage
> [!TIP]
> [π Read the documentation](https://nuxt-prepare.byjohann.dev)Add the `nuxt-prepare` module to your `nuxt.config.ts`:
```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:
```ts
// `server.prepare.ts`
import { defineNuxtPrepareHandler } from 'nuxt-prepare/config'export default defineNuxtPrepareHandler(async () => {
// Do some async magic here, e.g. fetch data from an APIreturn {
// 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](https://github.com/nodejs/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
- [Maronbeere](https://maronbeere.carrd.co) for his Chameleon pixel art.
- [McPizza0](https://github.com/McPizza0) for his inspirational [`nuxt-server-init`](https://github.com/McPizza0/nuxt-server-init) module.## License
[MIT](./LICENSE) License Β© 2023-PRESENT [Johann Schopplich](https://github.com/johannschopplich)