load(url, context, nextLoad)


  • url <string> resolve 链返回的 URL

    ¥url <string> The URL returned by the resolve chain

  • context <Object>

    • conditions <string[]> 相关 package.json 的导出条件

      ¥conditions <string[]> Export conditions of the relevant package.json

    • format <string> | <null> | <undefined> resolve 钩子链可选提供的格式。这可以是任何字符串值作为输入;输入值不需要符合下面描述的可接受返回值列表。

      ¥format <string> | <null> | <undefined> The format optionally supplied by the resolve hook chain. This can be any string value as an input; input values do not need to conform to the list of acceptable return values described below.

    • importAttributes <Object>

  • nextLoad <Function> 链中后续的 load 钩子,或者用户提供的最后一个 load 钩子之后的 Node.js 默认 load 钩子

    ¥nextLoad <Function> The subsequent load hook in the chain, or the Node.js default load hook after the last user-supplied load hook

    • url <string>

    • context <Object> | <undefined> 省略时,提供默认值。提供时,将优先合并默认值,优先于提供的属性。在默认 nextLoad 中,如果 url 指向的模块没有明确的模块类型信息,则 context.format 是必需的。

      ¥context <Object> | <undefined> When omitted, defaults are provided. When provided, defaults are merged in with preference to the provided properties. In the default nextLoad, if the module pointed to by url does not have explicit module type information, context.format is mandatory.

  • 返回:<Object> | <Promise> 异步版本要么采用包含以下属性的对象,要么采用将解析为此类对象的 Promise。同步版本仅接受同步返回的对象。

    ¥Returns: <Object> | <Promise> The asynchronous version takes either an object containing the following properties, or a Promise that will resolve to such an object. The synchronous version only accepts an object returned synchronously.

load 钩子提供了一种方式来定义确定网址应如何解释、检索、以及解析的自定义方法。它还负责验证导入属性。

¥The load hook provides a way to define a custom method of determining how a URL should be interpreted, retrieved, and parsed. It is also in charge of validating the import attributes.

format 的最终值必须是以下之一:

¥The final value of format must be one of the following:

format描述load 返回的 source 可接受的类型
'addon'加载 Node.js 插件<null>
'builtin'加载 Node.js 内置模块<null>
'commonjs'加载 Node.js CommonJS 模块<string> | <ArrayBuffer> | <TypedArray> | <null> | <undefined>
'json'加载 JSON 文件<string> | <ArrayBuffer> | <TypedArray>
'module'加载 ES 模块<string> | <ArrayBuffer> | <TypedArray>
'wasm'加载 WebAssembly 模块<ArrayBuffer> | <TypedArray>

source 的值对于类型 'builtin' 被忽略,因为目前无法替换 Node.js 内置(核心)模块的值。

¥The value of source is ignored for type 'builtin' because currently it is not possible to replace the value of a Node.js builtin (core) module.