加载器


稳定性: 1 - 实验

此 API 目前正在重新设计,并将继续更改。

要自定义默认的模块解析,则可以选择通过 Node.js 的 --experimental-loader ./loader-name.mjs 参数提供加载器钩子。

当使用钩子时,它们适用于入口点和所有 import 调用。 它们不适用于 require 调用;那些仍然遵循 CommonJS 规则。

加载器遵循 --require 的模式:

node \
  --experimental-loader unpkg \
  --experimental-loader http-to-https \
  --experimental-loader cache-buster

这些按以下顺序调用:cache-buster 调用 http-to-httpshttp-to-https 调用 unpkg

Stability: 1 - Experimental

This API is currently being redesigned and will still change.

To customize the default module resolution, loader hooks can optionally be provided via a --experimental-loader ./loader-name.mjs argument to Node.js.

When hooks are used they apply to the entry point and all import calls. They won't apply to require calls; those still follow CommonJS rules.

Loaders follow the pattern of --require:

node \
  --experimental-loader unpkg \
  --experimental-loader http-to-https \
  --experimental-loader cache-buster

These are called in the following sequence: cache-buster calls http-to-https which calls unpkg.