1.1.2 • Published 4 years ago
@dukai.net/hapi-plugin-loader v1.1.2
hapi-plugin-loader
One of the best feature of the hapi framework is the plug-in system. Usually in a case of the application not all plug-in comes from external sources. The application itself is organized into plug-ins. This little component is dynamically loading and registering plug-ins from a specific folder.
Installation:
npm install @dukai.net/hapi-plugin-loader
or:
yarn add @dukai.net/hapi-plugin-loader
Use:
const pluginLoader = require('@dukai.net/hapi-plugin-loader');
// Registering other usual plugins:
await server.register([
{
plugin: require('@hapi/inert')
},
{
plugin: require('@hapi/vision')
}
]);
// Using default options, where default path is 'plugins' and verbose mode is off
await pluginLoader(server, { root: __dirname });
// Alternatively using options:
await pluginLoader(server, {
root: __dirname,
path: 'my-weird-plugins-path',
verbose: true
});
Options:
// Default options
const options = {
root: null, // root folder must be specified!
path: 'plugins', // subpath from application root folder
verbose: false // if true, console log entries show which plugin got registered
};