tachybase_todo/docs/en-US/api/server/plugin.md

48 lines
1.2 KiB
Markdown
Raw Normal View History

# Plugin
2022-12-27 23:06:30 +08:00
## Overview
2022-12-27 23:06:30 +08:00
Plugins in NocoBase are in the form of `Class`. Custom plugins need to inherit the `Plugin` class.
2022-11-13 23:00:59 +08:00
```typescript
import { Plugin } from '@nocobase/server';
class MyPlugin extends Plugin {
2022-11-13 23:00:59 +08:00
// ...
}
app.plugin(MyPlugin, { name: 'my-plugin' });
```
2022-12-27 23:06:30 +08:00
## Plugin Lifecycle
2022-12-27 23:06:30 +08:00
Each plugin contains lifecycle methods, you can override these methods in order to execute them at certain stages during runtime. Lifecycle methods will be called by `Application` at certain stages, refer to [`Application` LifeCycle](./application.md).
### `beforeLoad()`
2022-12-27 23:06:30 +08:00
To implement the logic before plugin is loaded, such as event or class registration. The core interface can be accessed here, while other plugins are not available.
### `load()`
2022-12-27 23:06:30 +08:00
To implement the logic to load plugin, configurations and so on. Other plugin instances can be called in `load`, but not in `beforeLoad`.
### `install()`
2022-12-27 23:06:30 +08:00
To implement the logic to install plugin, such as data initialization.
2022-11-13 23:00:59 +08:00
### `afterAdd()`
2022-12-27 23:06:30 +08:00
To implement the logic after the add/addStatic of plugin.
2022-11-13 23:00:59 +08:00
### `afterEnable()`
2022-12-27 23:06:30 +08:00
To implement the logic after plugin is enabled.
### `afterDisable()`
2022-12-27 23:06:30 +08:00
To implement the logic after plugin is disabled.
### `remove()`
2022-12-27 23:06:30 +08:00
To implement the logic to remove plugin.