Runtime Plugin API
Plugin hook definition:
Writing Runtime Plugin
Hooks
Then are 2 kind of execution orders when calling Farm runtime plugin hooks:
serial: The hook is called ono by one by the order of plugins. All plugins would be called serially.first: Skip all left plugins oncetruthyvalue is returned.
Hook execution order:
name
type:string
The name of your runtime plugin.
bootstrap
hook type:serialtype:(moduleSystem: ModuleSystem) => void | Promise<void>
Invoked once when the module system is bootstrapped. Setup your plugin in this hook. Example:
moduleCreated
hook type:serialtype:(module: Module) => void | Promise<void>
Invoked after new module instances are created. You can read or update property of the new created module.
moduleCreated is called BEFORE the module is executed, so module.exports is always empty, use moduleInitialized instead if you want to access module.exports.
moduleInitialized
hook type:serialtype:(module: Module) => void | Promise<void>
Invoked after module initialization functions are called.
moduleCreated is called AFTER the module is executed, so module.exports is available is this hook.
readModuleCache
hook type:serialtype:(module: Module) => boolean | Promise<boolean>
Invoked after module caches are read, return true to skip cache reading and re-executed the module.
moduleNotFound
hook type:serialtype:(module: Module) => void | Promise<void>
Called when module is not registered.
loadResource
hook type:firsttype:(resource: Resource, targetEnv: 'browser' | 'node') => Promise<ResourceLoadResult>
called when loading resources, custom your resource loading in this hook.
- return
{ success: true }to indicate that this resources have been loaded successfully. - return
{ success: false, retryWithDefaultResourceLoader: true }to indicate that this resources have not been loaded successfully and should be retried with the default resource loader.
