(root: string, isTs: boolean)
| 799 | } |
| 800 | |
| 801 | function setupReactCompiler(root: string, isTs: boolean) { |
| 802 | // renovate: datasource=npm depName=@rolldown/plugin-babel |
| 803 | const babelPluginVersion = '0.2.3' |
| 804 | // renovate: datasource=npm depName=babel-plugin-react-compiler |
| 805 | const reactCompilerPluginVersion = '1.0.0' |
| 806 | // renovate: datasource=npm depName=@babel/core |
| 807 | const babelCoreVersion = '7.29.7' |
| 808 | // renovate: datasource=npm depName=@types/babel__core |
| 809 | const typesBabelCoreVersion = '7.20.5' |
| 810 | |
| 811 | editFile(path.resolve(root, 'package.json'), (content) => { |
| 812 | const asObject = JSON.parse(content) |
| 813 | const devDepsEntries = Object.entries(asObject.devDependencies) |
| 814 | devDepsEntries.push(['@rolldown/plugin-babel', `^${babelPluginVersion}`]) |
| 815 | devDepsEntries.push([ |
| 816 | 'babel-plugin-react-compiler', |
| 817 | `^${reactCompilerPluginVersion}`, |
| 818 | ]) |
| 819 | devDepsEntries.push(['@babel/core', `^${babelCoreVersion}`]) |
| 820 | if (isTs) { |
| 821 | devDepsEntries.push(['@types/babel__core', `^${typesBabelCoreVersion}`]) |
| 822 | } |
| 823 | devDepsEntries.sort() |
| 824 | asObject.devDependencies = Object.fromEntries(devDepsEntries) |
| 825 | return JSON.stringify(asObject, null, 2) + '\n' |
| 826 | }) |
| 827 | editFile( |
| 828 | path.resolve(root, `vite.config.${isTs ? 'ts' : 'js'}`), |
| 829 | (content) => { |
| 830 | return content |
| 831 | .replace( |
| 832 | `import react from '@vitejs/plugin-react'`, |
| 833 | `import react, { reactCompilerPreset } from '@vitejs/plugin-react' |
| 834 | import babel from '@rolldown/plugin-babel'`, |
| 835 | ) |
| 836 | .replace( |
| 837 | ' plugins: [react()],', |
| 838 | ` plugins: [ |
| 839 | react(), |
| 840 | babel({ presets: [reactCompilerPreset()] }) |
| 841 | ],`, |
| 842 | ) |
| 843 | }, |
| 844 | ) |
| 845 | updateReactCompilerReadme( |
| 846 | root, |
| 847 | 'The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.\n\nNote: This will impact Vite dev & build performances.', |
| 848 | ) |
| 849 | } |
| 850 | |
| 851 | function setupEslint(root: string, isTs: boolean) { |
| 852 | // renovate: datasource=npm depName=@eslint/js |
no test coverage detected