플러그인
Plugins are the building blocks of features in a Docusaurus site. 각 플러그인은 개별적인 기능을 가지고 있습니다. 플러그인은 presets을 통해 전체 묶음의 일부로 동작하고 배포됩니다.
Creating plugins
A plugin is a function that takes two parameters: context
and options
. 플러그인 인스턴스 오브젝트(또는 프로미스)를 반환합니다. 플러그인은 함수 또는 모듈로 만들 수 있습니다. For more information, refer to the plugin method references section.
Function definition
도큐사우루스 설정 파일을 아래와 같이 지정하면 플러그인을 함수처럼 사용할 수 있습니다.
docusaurus.config.js
export default {
// ...
plugins: [
async function myPlugin(context, options) {
// ...
return {
name: 'my-plugin',
async loadContent() {
// ...
},
async contentLoaded({content, actions}) {
// ...
},
/* other lifecycle API */
};
},
],
};
Module definition
별도 파일 또는 npm 패키지를 참조하는 모듈 경로로 플러그인을 사용할 수 있습니다.
docusaurus.config.js
export default {
// ...
plugins: [
// without options:
'./my-plugin',
// or with options:
['./my-plugin', options],
],
};
Then in the folder my-plugin
, you can create an index.js
such as this:
my-plugin/index.js
export default async function myPlugin(context, options) {
// ...
return {
name: 'my-plugin',
async loadContent() {
/* ... */
},
async contentLoaded({content, actions}) {
/* ... */
},
/* other lifecycle API */
};
}
You can view all plugins installed in your site using the debug plugin's metadata panel.
플러그인은 몇 가지 유형으로 제공됩니다.
package
: an external package you installedproject
: a plugin you created in your project, given to Docusaurus as a local file pathlocal
: a plugin created using the function definitionsynthetic
: a "fake plugin" Docusaurus created internally, so we take advantage of our modular architecture and don't let the core do much special work. 구현 세부 사항이기 때문에 메타데이터에서 확인할 수 없습니다.
You can access them on the client side with useDocusaurusContext().siteMetadata.pluginVersions
.