UNPKG

703 BJavaScriptView Raw
1function createPlugin(plugin, config) {
2 return {
3 handler: plugin,
4 config,
5 }
6}
7
8createPlugin.withOptions = function (pluginFunction, configFunction = () => ({})) {
9 const optionsFunction = function (options) {
10 return {
11 __options: options,
12 handler: pluginFunction(options),
13 config: configFunction(options),
14 }
15 }
16
17 optionsFunction.__isOptionsFunction = true
18
19 // Expose plugin dependencies so that `object-hash` returns a different
20 // value if anything here changes, to ensure a rebuild is triggered.
21 optionsFunction.__pluginFunction = pluginFunction
22 optionsFunction.__configFunction = configFunction
23
24 return optionsFunction
25}
26
27export default createPlugin