turbopackRustReactCompiler
experimental
使用 React Compiler 的原生 Rust 移植版本与 Turbopack 配合,以替代 Babel 转换。
experimental.turbopackRustReactCompiler 选项启用 React Compiler 的原生 Rust 版本,将其作为原生代码直接在 Turbopack 中运行,而不是像标准 Babel 版本那样通过 Node.js 运行。这通常带来明显的性能提升。
此选项作为实验性功能发布,以在成为默认选项之前收集反馈。
next.config.ts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
// 启用 React Compiler
reactCompiler: true,
experimental: {
// 使用 Rust 移植版本代替 Babel 转换
turbopackRustReactCompiler: true,
},
}
export default nextConfignext.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
// 启用 React Compiler
reactCompiler: true,
experimental: {
// 使用 Rust 移植版本代替 Babel 转换
turbopackRustReactCompiler: true,
},
}
module.exports = nextConfig小知识#
- 此选项要求启用
reactCompiler。它只选择运行哪种实现,但本身不会开启编译器。- 此选项仅受 Turbopack 支持。与 webpack 一起使用会抛出错误。
- 启用后,无需安装
babel-plugin-react-compiler。Rust 编译器在 Turbopack 内部原生运行。
有关如何使用编译器的详情,请参阅 reactCompiler 选项文档。
版本历史#
| 版本 | 变更 |
|---|---|
v16.3.0 | 引入了实验性的 turbopackRustReactCompiler 选项,用于原生 Rust React Compiler。 |