react-compiler
约 1 分钟阅读
标签:编译器
- 参考
- playground.react.dev
- react.dev/learn/react-compilerLinkreact.dev/learn/react-compiler参考 · https://playground.react.dev/ · https://react.dev/learn/react-compiler · ESBuild Plugin · https://gist.github.com/sikanhe/f9ac68dd4c78c914c29cc98e7b875466笔记:react-compiler
- ESBuild Plugin
pnpm add -D babel-plugin-react-compilerPackagesbabel-plugin-react-compilernpm Packagebabel-plugin-react-compilerNPM
// 部分
const ReactCompilerConfig = {
// annotation opt-in 模式,组件增加 'use memo'
compilationMode: 'annotation',
sources: (filename) => {
return filename.indexOf('src/path/to/dir') !== -1;
},
};vite
const ReactCompilerConfig = {
/* ... */
};
export default defineConfig(() => {
return {
plugins: [
react({
babel: {
plugins: [['babel-plugin-react-compiler', ReactCompilerConfig]],
},
}),
],
// ...
};
});export default defineConfig(({ command }) => {
const babelPlugins = [['babel-plugin-react-compiler', {}]];
if (command === 'serve') {
babelPlugins.push(['@babel/plugin-transform-react-jsx-development', {}]);
}
return {
plugins: [react({ babel: { plugins: babelPlugins } })],
};
});NextJS
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
reactCompiler: true,
},
};lint
npx -y react-compiler-healthcheck@latest --src 'src/**/*.{tsx,ts}'npm install eslint-plugin-react-compilerPackageseslint-plugin-react-compilernpm Packageeslint-plugin-react-compilerNPM
module.exports = {
plugins: ['eslint-plugin-react-compiler'],
rules: {
'react-compiler/react-compiler': 'error',
},
};关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- million笔记 · react compiler
aidenybai/million · MIT · <4kb · The Virtual DOM Replacement for React · https://million.dev/blog/virtual-dom · Diff the data, not the DOM.
References
其他外链4 条
- gist.github.com/hyrious/0ec637c7ec2214096cb591062ec73ee0gist.github.com/hyrious/0ec637c7ec2214096cb591062ec73ee0
- gist.github.com/sikanhe/f9ac68dd4c78c914c29cc98e7b875466gist.github.com/sikanhe/f9ac68dd4c78c914c29cc98e7b875466
- playground.react.devplayground.react.dev/
- react.dev/learn/react-compilerreact.dev/learn/react-compiler