源映射支持


【Source Map Support】

稳定性: 1 - 实验性

Node.js 支持 TC39 ECMA-426 源映射 格式(它被称为源映射第 3 版格式)。

【Node.js supports TC39 ECMA-426 Source Map format (it was called Source map revision 3 format).】

本节中的 API 是用于与源映射缓存交互的辅助工具。当启用源映射解析并且在模块的页脚中找到 源映射包含指令 时,会填充此缓存。

【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');