Skip to content

Commit 7895774

Browse files
authored
build: Ship components optimized with React Compiler (#992)
* Add React Compiler dependencies * Add React Compiler to Babel config * Target React 17 and above with the compiler runtime * Build js with babel; use typescript for declarations only * Add rollup bundle visualizer * Specify babel runtime version to prevent babel helpers from being inlined * Simplify react compiler logs
1 parent be4d290 commit 7895774

File tree

5 files changed

+282
-118
lines changed

5 files changed

+282
-118
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ docs/
1111
/styles/
1212
coverage/
1313
.vscode/
14+
stats.html

babel.config.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,45 @@ module.exports = {
1111
'@babel/preset-react',
1212
'@babel/preset-typescript',
1313
],
14-
plugins: ['@babel/proposal-object-rest-spread'],
14+
plugins: [
15+
[
16+
'babel-plugin-react-compiler',
17+
{
18+
// Support React 17 as a minimum
19+
target: '17',
20+
logger: {
21+
/**
22+
* @param {string | null} filename
23+
* @param {import('babel-plugin-react-compiler').LoggerEvent} event
24+
*/
25+
logEvent(filename, event) {
26+
if (
27+
event.kind === 'CompileError' ||
28+
event.kind === 'CompileSkip' ||
29+
event.kind === 'PipelineError'
30+
) {
31+
if (event.kind === 'CompileError') {
32+
console.warn(
33+
`\n[React Compiler] \x1b[33m${event.kind}\x1b[0m: ${filename}`,
34+
)
35+
}
36+
37+
if (event.detail?.reason) {
38+
console.error(`Reason: ${event.detail.reason}`)
39+
}
40+
}
41+
},
42+
},
43+
},
44+
],
45+
'@babel/proposal-object-rest-spread',
46+
[
47+
'@babel/plugin-transform-runtime',
48+
{
49+
// Prevent helpers from being inlined in the output code
50+
// https://babeljs.io/docs/babel-plugin-transform-runtime#version
51+
version: '^7.28.4',
52+
},
53+
],
54+
],
1555
}

0 commit comments

Comments
 (0)