Creating a Plugin
All plugins in BlueRain OS extend the Plugin Class.
Let's create a simple plugin that registers a new route /hello-world. When this route is called, HelloWorldComponent component should be rendered.
import { Plugin } from 'bluerain-os';
import HelloWorldComponent from './HelloWorldComponent';
class HelloWorldPlugin extends Plugin {
static pluginName = HelloWorldPlugin;
static slug = 'hello-world';
const hooks = {
'bluerain.routes':(routes, ctx) => {
routes.push({
path: '/hello-world',
component: HelloWorldComponent
})
});
}
const uses = {
hooks:['foo.bar']
}
initialize(config, ctx) {
}
}
export default HelloWorldPlugin;Notice that we also defined pluginName and slug static properties.
pluginNamedefines the name of the plugin. This is a required property and not providing one will throw error when you register the plugin.slugproperty defines the slug for your plugin. If you don't give one, then BlueRain will automatically create a slug by kebab casing thepluginNameproperty. It's a good convention manually define theslug. This slug is used to get an app from thePluginRegistry.hooksdefines the hooks plugin would add when added to the system.usesdefines the hooks plugin is running .
You can define even more Plugin properties. For a complete list, please refer to the API Reference.
Last updated