react-compiler supports compiling components with specified comments #50
Replies: 2 comments 1 reply
-
This is actually supported via the // babel.config.js
const ReactCompilerConfig = {
compilationMode: 'annotation',
};
module.exports = function () {
return {
plugins: [
['babel-plugin-react-compiler', ReactCompilerConfig],
],
};
}; function Compiled() {
"use memo";
// ...
}
function NotCompiledInAnnotationMode() {
// ...
}
function NotCompiledUnderAnyCircumstances() {
"use no memo";
// ...
} |
Beta Was this translation helpful? Give feedback.
-
FWIW, I went down this road as well. It made iteration easier because I could enable the React Compiler plugin in my build globally, and only had to modify source files to turn it on/off. The filename option means you have to modify the build config, which usually breaks incremental compilation and results in rebuilding the whole project. I eventually found that there wasn't much value in turning on the compiler for specific components and went back to the filename option. TBH the filename option in the compiler plugin feels a little redundant because you can do the same with Babel config overrides. You can get the best of both worlds by configuring babel so that:
This allows you to opt in entire folders without having to manage a bunch of annotation comments, but still letting you enable it on a specific component in dev without having to rebuild the whole project. |
Beta Was this translation helpful? Give feedback.
-
The above approach is a bit complicated to use in existing projects to specify compilation scope, but it is also a very good one.
This is a simpler way to compile a specified component.
This approach is more explicit and allows developers to more quickly identify the scope of react-compiler compilation.
Easy to test component performance before and after compilation.
Beta Was this translation helpful? Give feedback.
All reactions