Loading plugins
This section describes the way of loading plugins.
Background
Before creating a plugin, it is good to understand how plugins are being loaded. This topic was mentioned a little bit in Registries, but here are details.
Plugin is defined as separated Typescript file. It contains such information like id
, exposed configuration
, exposed slots
or injections
. Plugins are loaded via the import
and their parameters is mapped to proper registries.
When you are using CLI Setup, you can find generated utils.ts
file which contains function loadMyNoctoPlugins
. This function loads plugins and registers them.
For our and your convenience, we have decided for predefined structure which we are using in above function. We strongly recommend to follow the same structure, however if you do not like it, you can make your own structure. At the end, the most important part is to properly register plugins in registries.
Next sections assume our predefined structure and directory, which will work with utils.ts
.
Plugins directory
New plugins shall be created in src/plugins
folder of your Nocto project. You can make X nested directories there, so plugins can be grouped.
Plugin's entry point is index.tsx
(or index.ts
) - you define there its id
and plugin's functions.
ID Rules:
ID of the plugin shall be unique across the whole Nocto application. To keep consistency, here are the rules of assigning IDs:
- Nocto core - if the plugin is the part of Nocto core, its id starts with
@
and next is the name, e.g.@orders
. - User plugin - if the plugin is outside of the Nocto (you created it), please follow NPM approach so put
@yourcompany/plugin-name
.
As mentioned, plugin can have different functionalities so next sections will help you explain how to define them: