load(url, context, nextLoad)
-
url<string>resolve链返回的 URL¥
url<string> The URL returned by theresolvechain -
context<Object>-
conditions<string[]> 相关package.json的导出条件¥
conditions<string[]> Export conditions of the relevantpackage.json -
format<string> | <null> | <undefined>resolve钩子链可选提供的格式。这可以是任何字符串值作为输入;输入值不需要符合下面描述的可接受返回值列表。¥
format<string> | <null> | <undefined> The format optionally supplied by theresolvehook 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 subsequentloadhook in the chain, or the Node.js defaultloadhook after the last user-suppliedloadhook-
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 defaultnextLoad, if the module pointed to byurldoes not have explicit module type information,context.formatis mandatory.
-
-
返回:<Object> | <Promise> 异步版本要么采用包含以下属性的对象,要么采用将解析为此类对象的
Promise。同步版本仅接受同步返回的对象。¥Returns: <Object> | <Promise> The asynchronous version takes either an object containing the following properties, or a
Promisethat will resolve to such an object. The synchronous version only accepts an object returned synchronously.-
format<string> -
shortCircuit<undefined> | <boolean> 此钩子打算终止load钩子链的信号。默认值:false¥
shortCircuit<undefined> | <boolean> A signal that this hook intends to terminate the chain ofloadhooks. Default:false -
source<string> | <ArrayBuffer> | <TypedArray> Node.js 评估的来源¥
source<string> | <ArrayBuffer> | <TypedArray> The source for Node.js to evaluate
-
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-typescript' | 使用 TypeScript 语法加载 Node.js CommonJS 模块 | <string> | <ArrayBuffer> | <TypedArray> | <null> | <undefined> |
'commonjs' | 加载 Node.js CommonJS 模块 | <string> | <ArrayBuffer> | <TypedArray> | <null> | <undefined> |
'json' | 加载 JSON 文件 | <string> | <ArrayBuffer> | <TypedArray> |
'module-typescript' | 使用 TypeScript 语法加载 ES 模块 | <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.