docs: add info about merging strategy in app config (#21462)

This commit is contained in:
Wilson Pinto 2023-06-09 11:28:16 +02:00 committed by GitHub
parent 02ba4b30ac
commit 4fd756bae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,3 +91,32 @@ declare module 'nuxt/schema' {
// It is always important to ensure you import/export something when augmenting a type // It is always important to ensure you import/export something when augmenting a type
export {} export {}
``` ```
### App Config Merging Strategy in Layers
Nuxt uses a custom merging strategy for the `AppConfig` within the layers of your application.
This strategy is implemented using a [Function Merger](https://github.com/unjs/defu#function-merger), which allows defining a custom merging strategy for every key in `app.config` that has an array as value.
::alert{type=warning}
The Function Merger should only be used in the base `app.config` of your application.
::
Here's an example of how you can use:
::code-group
```ts [layer/app.config.ts]
export default defineAppConfig({
// Default array value
array: ['hello'],
})
```
```ts [app.config.ts]
export default defineAppConfig({
// Overwrite default array value by using a merger function
array: () => ['bonjour'],
})
```
::