Plugins give you the ability to modify Docz processes, default configurations and create hooks for build and render. This is a perfect place to integrate Docz with other tools.
To create a plugin you just need to use the createPlugin
method from docz-core
import { createPlugin } from 'docz-core' const myPlugin = () => createPlugin({ setConfig: (config) => /* ... */, onCreateBabelConfig: (args) => /* ... */, onCreateDevServer: (args) => /* ... */, onCreateWebpackConfig: (args) => /* ... */, modifyFiles: (files, args) => /* ... */, onPreBuild: () => /* ... */, onPostBuild: () => /* ... */, })
setConfig
Use to modify or create custom project configurations.
Config
onCreateWebpackConfig
Let plugins extend/mutate the site’s webpack configuration.
See also the documentation for setWebpackConfig.
stage {string}
The current build stage. One of ‘develop’, ‘develop-html’, ‘build-javascript’, or ‘build-html’
getConfig {function}
Returns the current webpack config
rules {object}
A set of preconfigured webpack config rules
loaders {object}
A set of preconfigured webpack config loaders
plugins {object}
A set of preconfigured webpack config plugins
actions {object}
exports.onCreateWebpackConfig = ({ stage, getConfig, rules, loaders, actions }) => { actions.setWebpackConfig({ module: { rules: [ { test: 'my-css', use: [loaders.style(), loaders.css()] }, ], }, }); }
onCreateBabelConfig
Use to modify babelrc configuration
stage {string}
The current build stage. One of ‘develop’, ‘develop-html’, ‘build-javascript’, or ‘build-html’
getConfig {function}
Returns the current webpack config
rules {object}
A set of preconfigured webpack config rules
loaders {object}
A set of preconfigured webpack config loaders
plugins {object}
A set of preconfigured webpack config plugins
actions {object}
exports.onCreateBabelConfig = ({ stage, getConfig, rules, loaders, actions }) => { actions.setBabelPlugin({ name: `babel-plugin-emotion`, options: { sourceMap: true, }, }) }
modifyFiles
Use to modify mdx files before parsing
string[]
export type ModifyFiles = (files: string[], args: Config) => string[]
onCreateDevServer
Run when gatsby develop server is started, its useful to add proxy and middleware to the dev server app
app {Express}
The Express app used to run the dev serverexports.onCreateDevServer = ({ app }) => { app.get('/hello', function (req, res) { res.send('hello world') }) }
onPreBuild
Method triggered before the build process
void
type OnPreBuild<C = any> = (config: C) => void
onPostBuild
Method triggered after the build process
void
type onPostBuild<C = any> = (config: C) => void