@acemarke/react-prod-sourcemaps

中文文档
0.3.2发布于 2026/08/06MITTypeScriptESM + CJS近 30 天下载 2.8万

A tool to update app sourcemaps with the original code of ReactDOM's production builds

原始使用文档
文档目录6 节
  1. Background
  2. Contents
  3. React Versions
  4. CLI Usage
  5. Build plugin usage
  6. Future Plans

react-prod-sourcemaps

A tool to update app sourcemaps with the original code of ReactDOM's production builds .

Background

React has never shipped sourcemaps for any of its production build artifacts. This makes it impossible to meaningfully debug errors inside of React in production. React's source code is already hard to understand in its original form - trying figure out what's happening when all you have is single-character variable names and no comments is impossible.

In 2023 I filed a React PR at https://github.com/facebook/react/pull/26446 that updated React's build pipeline to generate sourcemaps for production artifacts. It was eventually merged, but then later reverted. Instead, React 19 will ship with optimized but unminified prod artifacts. That means that app build steps will minify React's prod artifacts themselves, and thus React's source will be debuggable.

However, that doesn't help debug current versions of React.

I've done the work to check out the tagged source code for earlier React versions, rebuilt those versions locally, and verified that the artifacts are byte-for-byte identical. I've then backported the build pipeline changes from my PR onto those older checked-out versions, and built the sourcemaps that would have been generated for each version.

The actual build changes used can be seen here:

  • https://github.com/facebook/react/compare/v18.2.0...replayio:react:feature/react-sourcemaps-18.2.0

Contents

This package includes:

  • the actual sourcemaps
  • logic to search an input sourcemap for specific React and ReactDOM prod artifacts by content hash and replace them with the "original" pre-minified bundle source via the sourcemaps
  • a CLI tool that will load a given input sourcemap file and rewrite it
  • a build tool plugin that will automatically replace React package sourcemaps found in the app bundle

React Versions

This package currently includes sourcemaps for React and ReactDOM for these versions:

  • 18.3.1
  • 18.3.0
  • 18.2.0
  • 18.1.0
  • 18.0.0
  • 17.0.2
  • 17.0.1
  • 17.0.0

CLI Usage

yarn add @acemarke/react-prod-sourcemaps
./node_modules/.bin/react-prod-sourcemaps --inputFile path/to/your/appBuild/sourcemap.js.map
# Output file will currently be written to sourcemap.remapped.js.map

Build plugin usage

The build plugin is built using unplugin, meaning we currently supports webpack, esbuild, rollup, vite and rspack (experimental).

The plugin supports the following options:

keyvaluerequireddefaultrecommendedfunctionality
debugbooleannofalsefalseenables debug logging
preservebooleannofalsefalsepreserves original sourcemaps and outputs remapped sourcemaps under path/to/output/sourcemap/[name].js.remapped.map
mode"strict"noundefined"strict"causes the build plugin to throw an error if no sourcemap files are generated by the build tool

Warning: if sourcemap generation is not enabled by your build tool (or if it is not setup correctly), the plugin will silently fail and not perform any sourcemap remapping. We recommend setting using mode: "strict" in case you want the plugin to error in that case.

Webpack:

import { WebpackReactSourcemapsPlugin } from "@acemarke/react-prod-sourcemaps";

module.exports = {
  // ...webpack config
  devtool: "source-map", // or any other option that generates separate .map.js files
  plugins: [WebpackReactSourcemapsPlugin({ debug: false, preserve: false })],
};

esbuild:

import { EsbuildReactSourcemapsPlugin } from "@acemarke/react-prod-sourcemaps";

esbuild.build({
  // ...esbuild config
  sourcemap: true, // or any other option that generates separate .map.js files
  plugins: [EsbuildReactSourcemapsPlugin({ debug: false, preserve: false })],
});

Rollup:

import { RollupReactSourcemapsPlugin } from "@acemarke/react-prod-sourcemaps";

rollup({
  // ...rollup config
  output: {
    sourcemap: true, // or any other option that generates separate .map.js files
  },
  plugins: [RollupReactSourcemapsPlugin({ debug: false, preserve: false })],
});

Vite:

import { ViteReactSourcemapsPlugin } from "@acemarke/react-prod-sourcemaps";

vite.build({
  // ...vite config
  build: {
    sourcemap: true, // or any other option that generates separate .map.js files
  },
  plugins: [ViteReactSourcemapsPlugin({ debug: false, preserve: false })],
});

Future Plans

  • Add sourcemaps for more React versions
  • Add more options to the CLI tool:
    • Glob sourcemaps in a folder
    • Overwrite original sourcemap paths

版本与发布记录

@acemarke/react-prod-sourcemaps 共发布 12 个版本,首次发布于 2023/08/29;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.3.2latest2026/08/063 个月前
0.3.12024/09/142 年前
0.3.02024/09/142 年前
0.2.22024/08/272 年前
0.2.12023/09/283 年前
0.2.02023/09/273 年前

关于 @acemarke/react-prod-sourcemaps 的常见问题

@acemarke/react-prod-sourcemaps 是什么?

A tool to update app sourcemaps with the original code of ReactDOM's production builds

如何安装 @acemarke/react-prod-sourcemaps?

在项目目录运行 npm install @acemarke/react-prod-sourcemaps,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 react-prod-sourcemaps,可以用 npx react-prod-sourcemaps 直接运行。

@acemarke/react-prod-sourcemaps 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@acemarke/react-prod-sourcemaps 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@acemarke/react-prod-sourcemaps 可以商用吗?

@acemarke/react-prod-sourcemaps 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@acemarke/react-prod-sourcemaps 的下载量有多少?

根据 npm 官方下载统计,@acemarke/react-prod-sourcemaps 在 2026/10/05 – 2026/11/03 这 30 天内被下载 27,836 次,日均约 928 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@acemarke/react-prod-sourcemaps 还在维护吗?

最新版本 0.3.2 发布于 2026/08/06(3 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。