feat: improves plugin writability
This commit is contained in:
@@ -78,6 +78,8 @@ export default config;
|
|||||||
|
|
||||||
Payload Plugins are executed _after_ the incoming config is validated, sanitized, and default options are merged in.
|
Payload Plugins are executed _after_ the incoming config is validated, sanitized, and default options are merged in.
|
||||||
|
|
||||||
|
However, after all plugins are executed, the full config with all plugins will be re-sanitized.
|
||||||
|
|
||||||
## Simple example
|
## Simple example
|
||||||
|
|
||||||
Here is an example for how to automatically add a `lastModifiedBy` field to all Payload collections using a Plugin written in TypeScript.
|
Here is an example for how to automatically add a `lastModifiedBy` field to all Payload collections using a Plugin written in TypeScript.
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ export function buildConfig(config: Config): SanitizedConfig {
|
|||||||
const sanitized = sanitize(config);
|
const sanitized = sanitize(config);
|
||||||
|
|
||||||
if (Array.isArray(config.plugins)) {
|
if (Array.isArray(config.plugins)) {
|
||||||
return sanitized.plugins.reduce((configWithPlugins, plugin) => plugin(configWithPlugins), sanitized);
|
const configWithPlugins = sanitized.plugins.reduce((updatedConfig, plugin) => plugin(updatedConfig), sanitized);
|
||||||
|
return sanitize(configWithPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sanitized;
|
return sanitized;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type Email = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-use-before-define
|
// eslint-disable-next-line no-use-before-define
|
||||||
type Plugin = (config: SanitizedConfig) => SanitizedConfig;
|
type Plugin = (config: Config) => Config;
|
||||||
|
|
||||||
type GeneratePreviewURLOptions = {
|
type GeneratePreviewURLOptions = {
|
||||||
locale: string
|
locale: string
|
||||||
|
|||||||
Reference in New Issue
Block a user