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.
Learn more about Phenomic lifecycle
To know how to use a plugin see the configuration plugins
option.
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 plugins
option.
Examples
The best source of examples will be phenomic plugins included in our repository.
Plugins interesting part are usually located at phenomic/packages/plugin-*/src/index.js
.
Lifecycle methods
Here are the list of methods that allows you to interact with Phenomic lifecycle.
collect
The method 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
Used in
supportedFileTypes
+ transform
The method 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.
supportedFileTypes
Array of files extensions.
Example
Used in
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-transform-markdown/src/index.js
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-transform-asciidoc/src/index.js
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-transform-json/src/index.js
transform
Function that accepts an object and must return an result ready for Phenomic database:
Learn more about database entries in Content API documentation.
Used in
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-transform-markdown/src/index.js
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-transform-asciidoc/src/index.js
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-transform-json/src/index.js
build
Allows you to do a JavaScript bundle for client side rendering (CSR). Should return an object (map) of files (js and css) generated by the bundler.
Used in
buildForPrerendering
Allows you to do a JavaScript bundle for static side rendering (SSR).
The result will be passed to the getRoutes()
method. Your can return a promise.
Used in
getRoutes
Used in
resolveURLs
Allows to resolve all possibles URLS for static side rendering (SSR). Receive an object with the routes returned by getRoutes
.
Used in
renderStatic
Allows to statically generated some files. Receive an object that contains the result of buildForPrerendering
, build
and the url to render. Should return an array of files (a file is a path
+ its contents
). Promise are accepted.
Used in
renderDevServer
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.
Used in
addDevServerMiddlewares
Allows you to inject some express middleware for development server. Should return an array of express middlewares. Promise are accepted.
Used in
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-bundler-webpack/src/index.js
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-public-assets/src/index.js
- https://github.com/phenomic/phenomic/tree/master/packages/plugin-rss-feed/src/index.js
beforeBuild
Allows you to do anything before the build. Can return a promise.
Used in
afterBuild
Allows you to do anything after the build. Can return a promise.
extendAPI
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.
Example
Learn more about database Content API documentation.
Used in