koa-load-middlewares
Loads in any koa middlewares and attaches them to the global scope, or an object of your choice.
Inspired by gulp-load-plugins & load-grunt-tasks
Install
$ npm install --save koa-load-middlewares
Usage
Given a package.json
file that has some dependencies within:
Adding this into your koa server file:
var koa = ;var koaLoadMiddlewares = ;var middlewares = ;
Or, even shorter:
var middlewares = ;
Will result in the following happening (roughly, plugins are lazy loaded but in practice you won't notice any difference):
middlewaresswig = ;middlewaresbodyparser = ;
You can then use the plugins just like you would if you'd manually required them, but referring to them as middlewares.name()
, rather than just name()
.
This frees you up from having to manually require each koa middleware.
Options
You can pass in an object of options that are shown below: (the values for the keys are the defaults):
;