Вышел бета релиз React Compiler и ESLint плагина.
npm install -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta
Компилятор работает с 19 версией React, но можно запускать и с 17, 18, дополнительно установив react-compiler-runtime. Пример использования React Compiler в Vite:
// vite.config.js
const ReactCompilerConfig = { /* ... */ };
export default defineConfig(() => {
return {
plugins: [
react({
babel: {
plugins: [
["babel-plugin-react-compiler", ReactCompilerConfig],
],
},
}),
],
// ...
};
});
React Compiler можно запускать только на часть проекта, указав какие файлы обрабатывать:
const ReactCompilerConfig = {
sources: (filename) => {
return filename.indexOf('src/path/to/dir') !== -1;
},
};
Можно использовать ESLint плагин без использования компилятора. ESLint плагин позволяет разработчикам заблаговременно выявлять и исправлять нарушения правил React.
import reactCompiler from 'eslint-plugin-react-compiler'
export default [
{
plugins: {
'react-compiler': reactCompiler,
},
rules: {
'react-compiler/react-compiler': 'error',
},
},
]
https://react.dev/blog/2024/10/21/react-compiler-beta-release