turbopackRustReactCompiler
使用 Turbopack 运行 React Compiler 的原生 Rust 移植版本,而不是 Babel 转换。
此功能目前为实验性功能,可能会发生变化,不建议在生产环境中使用。你可以试用它,并在 GitHub 上分享你的反馈。
experimental.turbopackRustReactCompiler 选项会启用 React Compiler 的原生 Rust 版本,将其作为原生代码直接在 Turbopack 中运行,而不是像标准 Babel 版本那样通过 Node.js 运行。这通常会带来明显的性能提升。
此选项以实验性形式发布,以便在它成为默认选项之前收集反馈。
TypeScript
next.config.tsts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
// Enable the React Compiler
reactCompiler: true,
experimental: {
// Use the Rust port instead of the Babel transform
turbopackRustReactCompiler: true,
},
}
export default nextConfig
JavaScript
next.config.jsjs
/** @type {import('next').NextConfig} */
const nextConfig = {
// Enable the React Compiler
reactCompiler: true,
experimental: {
// Use the Rust port instead of the Babel transform
turbopackRustReactCompiler: true,
},
}
module.exports = nextConfig
须知
- 此选项需要先启用
reactCompiler。它只选择运行哪种实现,本身并不会开启编译器。- 此选项仅在 Turbopack 下受支持。与 webpack 一起使用时会抛出错误。
- 启用后,你无需安装
babel-plugin-react-compiler。Rust 编译器会在 Turbopack 内以原生方式运行。
有关如何使用编译器的详细信息,请参阅 reactCompiler 选项文档。
版本历史
| 版本 | 变更 |
|---|---|
v16.3.0 |
引入了用于原生 Rust 版 React Compiler 的实验性 turbopackRustReactCompiler 选项。 |