Load a submodule, plugin, or file.
require.resolve, but from one or more places, and
optionally global too.
npm install load-plugin
When bundled for the browser, a small file is included to warn that, when any of the below functions are invoked, the action is unsupported.
Say we’re in this project (with dependencies installed):
var load =load// => '/Users/tilde/projects/oss/load-plugin/node_modules/remark-lint/index.js'load// => '/Users/tilde/projects/oss/load-plugin/node_modules/@babel/helper-function-name/index.js'load// => '/Users/tilde/projects/oss/load-plugin/index.js'load// => [Function: lint]
Uses the standard node module loading strategy to require
name in each given
cwd (and optionally the global
If a prefix is given and
name is not a path,
prefix-name is also searched
(preferring these over non-prefixed modules).
If name starts with a scope (
@scope/name), the prefix is applied after it:
Prefix to search for (
Place or places to search from (
Whether to look for
name in global places (
defaults to whether global is detected).
If this is nully,
load-plugin will detect if it’s currently running in global
mode: either because it’s in Electron, or because a globally installed package
is running it.
Note: Electron runs its own version of Node instead of your system Node.
That means global packages cannot be found, unless you’ve set-up a
.npmrc or are using nvm to manage your system node.
The results of
requireing the first path that exists.
requireing an existing path fails, or if no existing path exists.
Accepts the same parameters as
loadPlugin but returns an
absolute path for
name instead of requiring it, and
null if it cannot be