From 56cd50e0edefbd894c115369ea67efac731df52b Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sun, 5 Apr 2026 18:38:06 -0700 Subject: [PATCH] add react compiler --- electron.vite.config.ts | 5 +++-- eslint.config.mjs | 2 +- package.json | 1 + pnpm-lock.yaml | 23 ++++++++++------------- remote.vite.config.ts | 4 ++-- tsconfig.node.json | 10 +++++++++- vite.react-plugin.ts | 9 +++++++++ web.vite.config.ts | 5 +++-- 8 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 vite.react-plugin.ts diff --git a/electron.vite.config.ts b/electron.vite.config.ts index 5b60df40e..491ee0032 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -1,10 +1,11 @@ -import react from '@vitejs/plugin-react'; import { externalizeDepsPlugin, UserConfig } from 'electron-vite'; import { resolve } from 'path'; import conditionalImportPlugin from 'vite-plugin-conditional-import'; import dynamicImportPlugin from 'vite-plugin-dynamic-import'; import { ViteEjsPlugin } from 'vite-plugin-ejs'; +import { createReactPlugin } from './vite.react-plugin'; + const currentOSEnv = process.platform; const electronRendererTarget = 'chrome87'; @@ -64,7 +65,7 @@ const config: UserConfig = { localsConvention: 'camelCase', }, }, - plugins: [react(), ViteEjsPlugin({ web: false })], + plugins: [createReactPlugin(), ViteEjsPlugin({ web: false })], resolve: { alias: { '/@/i18n': resolve('src/i18n'), diff --git a/eslint.config.mjs b/eslint.config.mjs index 6cb0fda89..1945d6c4a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -25,7 +25,7 @@ export default tseslint.config( 'react-refresh': eslintPluginReactRefresh, }, rules: { - ...eslintPluginReactHooks.configs.recommended.rules, + ...eslintPluginReactHooks.configs['recommended-latest'].rules, ...eslintPluginReactRefresh.configs.vite.rules, '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-duplicate-enum-values': 'off', diff --git a/package.json b/package.json index ac28121b2..eef929d3b 100644 --- a/package.json +++ b/package.json @@ -158,6 +158,7 @@ "@types/source-map-support": "^0.5.10", "@types/ws": "^8.18.1", "@vitejs/plugin-react": "^5.2.0", + "babel-plugin-react-compiler": "^1.0.0", "concurrently": "^9.2.1", "cross-env": "^10.1.0", "electron": "^39.8.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 872196e63..51ca38fff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -262,6 +262,9 @@ importers: '@vitejs/plugin-react': specifier: ^5.2.0 version: 5.2.0(vite@7.3.1(@types/node@24.12.2)(jiti@2.6.1)(sass-embedded@1.89.0)(sugarss@5.0.1(postcss@8.5.8))(terser@5.46.1)(yaml@2.8.1)) + babel-plugin-react-compiler: + specifier: ^1.0.0 + version: 1.0.0 concurrently: specifier: ^9.2.1 version: 9.2.1 @@ -1912,79 +1915,66 @@ packages: resolution: {integrity: sha512-L+34Qqil+v5uC0zEubW7uByo78WOCIrBvci69E7sFASRl0X7b/MB6Cqd1lky/CtcSVTydWa2WZwFuWexjS5o6g==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.60.1': resolution: {integrity: sha512-n83O8rt4v34hgFzlkb1ycniJh7IR5RCIqt6mz1VRJD6pmhRi0CXdmfnLu9dIUS6buzh60IvACM842Ffb3xd6Gg==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.60.1': resolution: {integrity: sha512-Nql7sTeAzhTAja3QXeAI48+/+GjBJ+QmAH13snn0AJSNL50JsDqotyudHyMbO2RbJkskbMbFJfIJKWA6R1LCJQ==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.60.1': resolution: {integrity: sha512-+pUymDhd0ys9GcKZPPWlFiZ67sTWV5UU6zOJat02M1+PiuSGDziyRuI/pPue3hoUwm2uGfxdL+trT6Z9rxnlMA==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-loong64-gnu@4.60.1': resolution: {integrity: sha512-VSvgvQeIcsEvY4bKDHEDWcpW4Yw7BtlKG1GUT4FzBUlEKQK0rWHYBqQt6Fm2taXS+1bXvJT6kICu5ZwqKCnvlQ==} cpu: [loong64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-loong64-musl@4.60.1': resolution: {integrity: sha512-4LqhUomJqwe641gsPp6xLfhqWMbQV04KtPp7/dIp0nzPxAkNY1AbwL5W0MQpcalLYk07vaW9Kp1PBhdpZYYcEw==} cpu: [loong64] os: [linux] - libc: [musl] '@rollup/rollup-linux-ppc64-gnu@4.60.1': resolution: {integrity: sha512-tLQQ9aPvkBxOc/EUT6j3pyeMD6Hb8QF2BTBnCQWP/uu1lhc9AIrIjKnLYMEroIz/JvtGYgI9dF3AxHZNaEH0rw==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-ppc64-musl@4.60.1': resolution: {integrity: sha512-RMxFhJwc9fSXP6PqmAz4cbv3kAyvD1etJFjTx4ONqFP9DkTkXsAMU4v3Vyc5BgzC+anz7nS/9tp4obsKfqkDHg==} cpu: [ppc64] os: [linux] - libc: [musl] '@rollup/rollup-linux-riscv64-gnu@4.60.1': resolution: {integrity: sha512-QKgFl+Yc1eEk6MmOBfRHYF6lTxiiiV3/z/BRrbSiW2I7AFTXoBFvdMEyglohPj//2mZS4hDOqeB0H1ACh3sBbg==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.60.1': resolution: {integrity: sha512-RAjXjP/8c6ZtzatZcA1RaQr6O1TRhzC+adn8YZDnChliZHviqIjmvFwHcxi4JKPSDAt6Uhf/7vqcBzQJy0PDJg==} cpu: [riscv64] os: [linux] - libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.60.1': resolution: {integrity: sha512-wcuocpaOlaL1COBYiA89O6yfjlp3RwKDeTIA0hM7OpmhR1Bjo9j31G1uQVpDlTvwxGn2nQs65fBFL5UFd76FcQ==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.60.1': resolution: {integrity: sha512-77PpsFQUCOiZR9+LQEFg9GClyfkNXj1MP6wRnzYs0EeWbPcHs02AXu4xuUbM1zhwn3wqaizle3AEYg5aeoohhg==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.60.1': resolution: {integrity: sha512-5cIATbk5vynAjqqmyBjlciMJl1+R/CwX9oLk/EyiFXDWd95KpHdrOJT//rnUl4cUcskrd0jCCw3wpZnhIHdD9w==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-openbsd-x64@4.60.1': resolution: {integrity: sha512-cl0w09WsCi17mcmWqqglez9Gk8isgeWvoUZ3WiJFYSR3zjBQc2J5/ihSjpl+VLjPqjQ/1hJRcqBfLjssREQILw==} @@ -2428,6 +2418,9 @@ packages: peerDependencies: '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 + babel-plugin-react-compiler@1.0.0: + resolution: {integrity: sha512-Ixm8tFfoKKIPYdCCKYTsqv+Fd4IJ0DQqMyEimo+pxUOMUR9cVPlwTrFt9Avu+3cb6Zp3mAzl+t1MrG2fxxKsxw==} + balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -8151,6 +8144,10 @@ snapshots: transitivePeerDependencies: - supports-color + babel-plugin-react-compiler@1.0.0: + dependencies: + '@babel/types': 7.29.0 + balanced-match@1.0.2: {} balanced-match@2.0.0: {} diff --git a/remote.vite.config.ts b/remote.vite.config.ts index 035003319..b92095c9a 100644 --- a/remote.vite.config.ts +++ b/remote.vite.config.ts @@ -1,9 +1,9 @@ -import react from '@vitejs/plugin-react'; import path from 'path'; import { defineConfig, normalizePath } from 'vite'; import { ViteEjsPlugin } from 'vite-plugin-ejs'; import { version } from './package.json'; +import { createReactPlugin } from './vite.react-plugin'; export default defineConfig({ build: { @@ -35,7 +35,7 @@ export default defineConfig({ }, }, plugins: [ - react(), + createReactPlugin(), ViteEjsPlugin({ prod: process.env.NODE_ENV === 'production', root: normalizePath(path.resolve(__dirname, './src/remote')), diff --git a/tsconfig.node.json b/tsconfig.node.json index 16ddd05db..851753f9e 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,6 +1,14 @@ { "extends": "@electron-toolkit/tsconfig/tsconfig.node.json", - "include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "src/i18n/**/*", "src/types/**/*", "src/shared/**/*"], + "include": [ + "electron.vite.config.*", + "vite.react-plugin.ts", + "src/main/**/*", + "src/preload/**/*", + "src/i18n/**/*", + "src/types/**/*", + "src/shared/**/*" + ], "compilerOptions": { "composite": true, "types": ["electron-vite/node"], diff --git a/vite.react-plugin.ts b/vite.react-plugin.ts new file mode 100644 index 000000000..0f81e300e --- /dev/null +++ b/vite.react-plugin.ts @@ -0,0 +1,9 @@ +import react from '@vitejs/plugin-react'; + +export function createReactPlugin() { + return react({ + babel: { + plugins: ['babel-plugin-react-compiler'], + }, + }); +} diff --git a/web.vite.config.ts b/web.vite.config.ts index 657ab128b..fcaa17095 100644 --- a/web.vite.config.ts +++ b/web.vite.config.ts @@ -1,9 +1,10 @@ -import react from '@vitejs/plugin-react'; import path from 'path'; import { defineConfig, normalizePath } from 'vite'; import { ViteEjsPlugin } from 'vite-plugin-ejs'; import { VitePWA } from 'vite-plugin-pwa'; +import { createReactPlugin } from './vite.react-plugin'; + export default defineConfig({ base: './', build: { @@ -63,7 +64,7 @@ export default defineConfig({ ], }, plugins: [ - react(), + createReactPlugin(), ViteEjsPlugin({ root: normalizePath(path.resolve(__dirname, './src/renderer')), web: true,