Plugins are the strength of Phenomic and what make it so flexible and reusable. Phenomic allows you to interact with it at several state of the process depending on what you need.
To know how to use a plugin see the configuration
Creating your plugin
A plugin can take the form of a node_modules or directly a function in the configuration. It must be a function that returns object.
Note that you can also export using ES2015 export
If your plugin accepts options, you can use the first parameter of the function. This parameter will receive the option that you can inject via the configuration
The best source of examples will be phenomic plugins included in our repository.
Plugins interesting part are usually located at
Here are the list of methods that allows you to interact with Phenomic lifecycle.
collect is useful if you plan to use Content API. It allows you to collect your data before rendering and to inject it into the database.
It receive the database and all transformers plugin as arguments
transform is useful if you plan to use Content API. It allows you to transform files (that match
supportedFileTypes – array of files extensions) as something ready for Phenomic database.
Array of files extensions.
Function that accepts an object and must return an result ready for Phenomic database:
Learn more about database entries in Content API documentation.
The result will be passed to the
getRoutes() method. Your can return a promise.
Allows to resolve all possibles URLS for static side rendering (SSR). Receive an object with the routes returned by
Allows to statically generated some files. Receive an object that contains the result of
build and the url to render. Should return an array of files (a file is a
path + its
contents). Promise are accepted.
Allows to generated the HTML for the entry point for development. Receive an object that contains the result of
build and the url to render.
Should return some HTML.
Allows you to inject some express middleware for development server. Should return an array of express middlewares. Promise are accepted.
Allows you to do anything before the build. Can return a promise.
Allows you to do anything after the build. Can return a promise.
Allows to extend the API with new endpoints. Handy for custom queries to the database. Accept an object with API (express server) and Phenomic databse to hit directly on it.
Learn more about database Content API documentation.