reactjs / reactjs/react.dev

[Typo]: The alternative way to configure react compiler with vitejs doesn't work

未关闭
#8,148 1 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

type: typos
主要语言
JavaScript
星标
11.8k
派生
7.9k
平均合并
1 天 11 小时
30 天内合并 PR
11

描述

Summary

The alternative way to configure react-compiler with Vitejs, which is to declare the Babel configuration separately, doesn't actually work.

Page

https://react.dev/learn/react-compiler/installation#vite

Details

Note that I'm talking about a TypeScript scenario.

I figure this is because of the default filter parameter which is specfieid to be jsx (you can find it here).

For the fix, it seems the babel config provided for react-router case works well with vite-plugin-react. so maybe we can use that, it would look something like this:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import babel from 'vite-plugin-babel';

const ReactCompilerConfig = { /* ... */ };

export default defineConfig({
  plugins: [
    react(),
    babel({
      filter: /\.[jt]sx?$/,
      babelConfig: {
        presets: ["@babel/preset-typescript"],
        plugins: [
          ["babel-plugin-react-compiler", ReactCompilerConfig],
        ],
      },
    }),
  ],
});

Also, maybe it's not a good idea to talk about it here, but I suggest to also have a guide for how the configuration should look like for a vite user who uses JavaScript (jsx) instead of TypeScript because apparently removing the TypeScript babel preset doesn't turn it into a JavaScript configuration; it requires more adjustments.
so maybe considering all of this, we are better off just removing the alternative, since it causes more problems than it solves 😅

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 react.dev/learn/react-compiler/installation#vite 开始,将备用 Babel 配置与 #usage-with-react-router 中的 React Router 示例进行比较。验证 TypeScript 和 JavaScript/Vite 的情况,然后更新页面,使文档中的设置能够正常工作,或者删除备用方案;确认最终的说明和示例保持一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, react, typescript, vite
领域
documentation
Issue 类型
文档
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。