2022-10-31 03:52:17 +00:00
# Plugin
2022-12-27 15:06:30 +00:00
## Overview
2022-10-31 03:52:17 +00:00
2022-12-27 15:06:30 +00:00
Plugins in NocoBase are in the form of `Class` . Custom plugins need to inherit the `Plugin` class.
2022-11-13 15:00:59 +00:00
```typescript
import { Plugin } from '@nocobase/server';
2022-10-31 03:52:17 +00:00
class MyPlugin extends Plugin {
2022-11-13 15:00:59 +00:00
// ...
2022-10-31 03:52:17 +00:00
}
app.plugin(MyPlugin, { name: 'my-plugin' });
```
2022-12-27 15:06:30 +00:00
## Plugin Lifecycle
2022-10-31 03:52:17 +00:00
2022-12-27 15:06:30 +00: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 ).
2022-10-31 03:52:17 +00:00
### `beforeLoad()`
2022-12-27 15:06:30 +00: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.
2022-10-31 03:52:17 +00:00
### `load()`
2022-12-27 15:06:30 +00:00
To implement the logic to load plugin, configurations and so on. Other plugin instances can be called in `load` , but not in `beforeLoad` .
2022-10-31 03:52:17 +00:00
### `install()`
2022-12-27 15:06:30 +00:00
To implement the logic to install plugin, such as data initialization.
2022-10-31 03:52:17 +00:00
2022-11-13 15:00:59 +00:00
### `afterAdd()`
2022-12-27 15:06:30 +00:00
To implement the logic after the add/addStatic of plugin.
2022-11-13 15:00:59 +00:00
2022-10-31 03:52:17 +00:00
### `afterEnable()`
2022-12-27 15:06:30 +00:00
To implement the logic after plugin is enabled.
2022-10-31 03:52:17 +00:00
### `afterDisable()`
2022-12-27 15:06:30 +00:00
To implement the logic after plugin is disabled.
2022-10-31 03:52:17 +00:00
### `remove()`
2022-12-27 15:06:30 +00:00
To implement the logic to remove plugin.