You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `meta` setting is an advanced feature. Instead of using `meta`, consider using <Link href="/file-env" noBreadcrumb={true} /> or <Link href="/extensions">Vike Extensions</Link> (they use `meta` on your behalf).
- **Modifying the environment of existing hooks**.
@@ -86,6 +89,7 @@ async function data(pageContext: PageContextServer) {
86
89
}
87
90
```
88
91
92
+
89
93
## Example: `+sql`
90
94
91
95
Similarly to the previous example, another common use case is to enable pages to define their data requirements as SQL queries.
@@ -383,6 +387,33 @@ async function onRenderClient(pageContext: PageContextClient) {
383
387
```
384
388
385
389
390
+
## Example: `+metadata`
391
+
392
+
Another common use case is defining page metadata.
393
+
394
+
```ts
395
+
// /pages/+config.ts
396
+
397
+
importtype { Config } from'vike/types'
398
+
399
+
exportdefault {
400
+
meta: {
401
+
// Create +metadata setting
402
+
metadata: {
403
+
// Make +metadata available to all pages
404
+
eager: true,
405
+
env: {
406
+
server: true,
407
+
client: true
408
+
}
409
+
}
410
+
}
411
+
} satisfiesConfig
412
+
```
413
+
414
+
See more examples at <Linkhref="/markdown#metadata" />.
415
+
416
+
386
417
## Example: modify `+data` env
387
418
388
419
You can use `meta` to change the environment in which built-in hooks are loaded. For example, you can change the environment of the <Linkhref="/data">`data()` hook</Link> from `{ server: true, client: false }` to `{ server: true, client: true }`.
@@ -457,22 +488,31 @@ import type { Config } from 'vike/types'
457
488
458
489
exportdefault {
459
490
meta: {
460
-
someSettingOrHook: {
461
-
// [Required] Defines the environment in which the config value is loaded.
491
+
someConfig: {
492
+
// [Required] Defines the environment in which the config value is loaded
462
493
env: {
463
-
// Load the config value on the server. [Required]
494
+
//[Required] Load config value on the server
464
495
server: true,
465
-
// Load the config value on the client. [Required]
496
+
//[Required] Load config value on the client
466
497
client: true,
467
-
// Load the config value at config-time (when Vike loads +config.ts files). [Optional]
468
-
config: false// default value
498
+
// [Optional] Load config value at config-time (when Vike loads +config.ts files)
499
+
config: false, // default value
500
+
// [Optional] Load config value only in prod/dev (`true`/`false` => only prod/dev)
501
+
production: undefined// default value
469
502
},
470
503
471
-
// [Optional] Whether config values should be merged (instead of overridden).
504
+
// [Optional] Whether config values should be merged (instead of overridden)
472
505
cumulative: false, // default value
473
506
474
-
// [Optional] Function called when the config value is loaded at config-time.
475
-
// Requires `env.config` to be `true`.
507
+
// [Optional] Whether all config values should be loaded at initialization. This
508
+
// means that all values of all pages are always available.
509
+
eager: false, // default value
510
+
511
+
// [Optional] Whether the config value must be defined globally (not per-page)
512
+
global: false, // default value
513
+
514
+
// [Optional] Function called when the config value is loaded at config-time. Note
515
+
// that `effect()` requires `env.config` to be `true`.
476
516
effect({ configDefinedAt, configValue }) {
477
517
if (someCondition) {
478
518
// This config object is merged with the current one.
@@ -485,7 +525,11 @@ export default {
485
525
}
486
526
}
487
527
}
488
-
}
528
+
},
529
+
530
+
// [Optional] Whether the config value affects Vite's configuration and therefore
531
+
// whether a change during dev (HMR) should trigger Vite to reload its config.
0 commit comments