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 摘要。