源映射支持
¥Source Map Support
¥Stability: 1 - Experimental
Node.js 支持 TC39 ECMA-426 源映射 格式(之前称为 Source map 修订版 3 格式)。
¥Node.js supports TC39 ECMA-426 Source Map format (it was called Source map revision 3 format).
本节中的 API 用于辅助与 Source map 缓存交互。当启用源映射解析并且在模块的页脚中找到 源映射包含指令 时,将填充此缓存。
¥The APIs in this section are helpers for interacting with the source map cache. This cache is populated when source map parsing is enabled and source map include directives are found in a modules' footer.
要启用源映射解析,Node.js 必须在运行过程中使用 --enable-source-maps
标志,或者通过设置 NODE_V8_COVERAGE=dir
启用代码覆盖率,或者通过 module.setSourceMapsSupport()
以编程方式启用。
¥To enable source map parsing, Node.js must be run with the flag
--enable-source-maps
, or with code coverage enabled by setting
NODE_V8_COVERAGE=dir
, or be enabled programmatically via
module.setSourceMapsSupport()
.
// module.mjs
// In an ECMAScript module
import { findSourceMap, SourceMap } from 'node:module';
// module.cjs
// In a CommonJS module
const { findSourceMap, SourceMap } = require('node:module');