registerPlugin function is the primary way to extend Scully’s functionality by registering custom plugins. It allows you to hook into various stages of Scully’s build process.
Signature
Parameters
The type of plugin to register. Must be one of:
'router'- Discovers routes in your application'render'or'postProcessByHtml'- Processes HTML as a string'postProcessByDom'- Processes HTML using JSDOM'fileHandler'- Handles specific file extensions'routeProcess'- Processes routes before rendering'allDone'- Runs after all routes are rendered'beforeAll'- Runs before route discovery'routeDiscoveryDone'- Runs after route discovery completes'enterprise'- Enterprise-level plugin hooks'scullySystem'- Internal system plugins
Unique identifier for the plugin. Use a string constant (e.g.,
'myPlugin' as const) instead of symbols.The plugin implementation function. The signature varies based on the plugin type.
Additional options based on plugin type:
- For
'router'plugins: AConfigValidatorfunction that validates route configuration - For
'fileHandler'plugins: An array of alternate file extensions (e.g.,['.md', '.markdown']) - For
'beforeAll'or'routeProcess'plugins: A priority number (default: 100)
Additional registration options:
replaceExistingPlugin: Set totrueto replace an existing plugin with the same name (default:false)
Plugin Types
Router Plugins
Router plugins discover and generate routes for your application.Render Plugins
Render plugins modify the HTML after it has been rendered.DOM Plugins
DOM plugins work with the JSDOM representation for more complex manipulations.File Handler Plugins
File handler plugins process content files with specific extensions.Route Process Plugins
Route process plugins modify the route list before rendering.Lifecycle Plugins
Plugins that run at specific lifecycle points.Error Handling
Best Practices
Use string constants instead of symbols
Use string constants instead of symbols
While symbols are supported, they’re deprecated. Use string constants with
as const for better debugging:Always provide validators for router plugins
Always provide validators for router plugins
Router plugins should include a validator function to check configuration:
Handle errors gracefully
Handle errors gracefully
Plugin functions should catch and handle errors to prevent build failures:
Use appropriate priorities
Use appropriate priorities
For
beforeAll and routeProcess plugins, set priorities based on execution order needs:- Lower numbers (e.g., 50) run first
- Default priority is 100
- Higher numbers (e.g., 150) run last
Source Reference
Source:libs/scully/src/lib/pluginManagement/pluginRepository.ts:46
Related
findPlugin
Retrieve a registered plugin by name
Plugin System
Learn more about Scully’s plugin architecture
Creating Plugins
Step-by-step guide to creating custom plugins
Plugin Types
Detailed documentation for each plugin type

