y-server-load-plugins
Loads y-server plugins from package dependencies and attaches them to an object of your choice.
Install
$ npm install --save-dev y-server-load-plugins
Usage
Given a package.json
file that has some dependencies within:
Adding this into your y-server.config.js
:
var yServerLoadPlugins = ;var plugins = ;
Or, even shorter:
var plugins = ;
Will result in the following happening (roughly, plugins are lazy loaded but in practice you won't notice any difference):
pluginsstatic = ;pluginstemplate = ;
This frees you up from having to manually require each y-server plugin.
Options
You can pass in an object of options that are shown below: (the values for the keys are the defaults,most same to the y-server-load-plugins):
;
config
locations
Multiple While it's possile to grab plugins from another location, often times you may want to extend from another package that enables you to keep your own package.json
free from duplicates, but still add in your own plugins that are needed for your project. Since the config
option accepts an object, you can merge together multiple locations using the lodash.merge package:
var merge = ; var packages = ; // Utilitiesvar $ = ;
postRequireTransforms
This enables you to transform the plugin after it has been required by y-server-load-plugins.
For example, one particular plugin (let's say, y-server-plugins-foo
), might need you to call a function to configure it before it is used. So you would end up with:
var $ = ;$foo = $foo;
This is a bit messy. Instead you can pass a postRequireTransforms
object which will enable you to do this:
var $ = postRequireTransforms: { return foo; } ; $foo // is already configured
Everytime a plugin is loaded, we check to see if a transform is defined, and if so, we call that function, passing in the loaded plugin. Whatever this function returns is then used as the value that's returned by y-server-load-plugins.
For 99% of y-server-plugins you will not need this behaviour, but for the odd plugin it's a nice way of keeping your code cleaner.
Override Pattern
Configuring the pattern
option would override the built-in ['y-server-plugins-*'
. If overridePattern: false
, the configured pattern
will now extends the built-in matching.
Changelog
0.0.1
- initial release