examples/with-algolia-search/src/docs/references/creating-plugins.mdx
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) => /* ... */,
modifyEntry: (args) => /* ... */,
onPreBuild: () => /* ... */,
onPostBuild: () => /* ... */,
})
setConfigUse to modify or create custom project configurations.
ConfigonCreateWebpackConfigLet 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()]
},
],
},
});
}
onCreateBabelConfigUse 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: `@emotion/babel-plugin`,
options: {
sourceMap: true,
},
})
}
modifyFilesUse to modify mdx files before parsing
string[]export type ModifyFiles = (files: string[], args: Config) => string[]
modifyEntryUse to modify files entry after created
Entryexport type ModifyEntry = (entry: Entry, args: Config) => Entry
onCreateDevServerRun 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')
})
}
onPreBuildMethod triggered before the build process
voidtype OnPreBuild<C = any> = (config: C) => void
onPostBuildMethod triggered after the build process
voidtype onPostBuild<C = any> = (config: C) => void