Skip to content

Commit 27ca8a3

Browse files
committed
Set up react-compiler in webpack, babel build configs
1 parent fbc94c1 commit 27ca8a3

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const path = require('path');
22

3+
const ReactCompilerConfig = {
4+
target: '17',
5+
sources: (filename) => {
6+
return (
7+
filename.indexOf('ui/') !== -1 &&
8+
filename.indexOf('ui/pages/confirmations') === -1 &&
9+
filename.indexOf('ui/components/app/identity') === -1
10+
);
11+
},
12+
};
13+
314
module.exports = function (api) {
415
api.cache(false);
516
return {
@@ -10,6 +21,7 @@ module.exports = function (api) {
1021
browsers: ['chrome >= 89', 'firefox >= 89'],
1122
},
1223
plugins: [
24+
['babel-plugin-react-compiler', ReactCompilerConfig],
1325
// `browserify` is old and busted, and doesn't support `??=` (and other
1426
// logical assignment operators). This plugin lets us target es2020-level
1527
// browsers (except we do still end up with transpiled logical assignment

development/webpack/constants.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineReactCompilerLoaderOption } from 'react-compiler-webpack';
2+
3+
export const reactCompilerOptions = {
4+
target: '17',
5+
logger: null,
6+
gating: null,
7+
noEmit: true,
8+
compilationMode: 'all',
9+
eslintSuppressionRules: null,
10+
flowSuppressions: false,
11+
ignoreUseNoForget: false,
12+
sources: (filename) => {
13+
return (
14+
filename.indexOf('ui/') !== -1 &&
15+
filename.indexOf('ui/pages/confirmations') === -1 &&
16+
filename.indexOf('ui/components/app/identity') === -1
17+
);
18+
},
19+
enableReanimatedCheck: false,
20+
} as const satisfies Parameters<typeof defineReactCompilerLoaderOption>[0];

development/webpack/webpack.config.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import rtlCss from 'postcss-rtlcss';
1818
import autoprefixer from 'autoprefixer';
1919
import discardFonts from 'postcss-discard-font-face';
2020
import type ReactRefreshPluginType from '@pmmmwh/react-refresh-webpack-plugin';
21+
import {
22+
defineReactCompilerLoaderOption,
23+
reactCompilerLoader,
24+
} from 'react-compiler-webpack';
2125
import tailwindcss from 'tailwindcss';
2226
import { loadBuildTypesConfig } from '../lib/build-type';
2327
import {
@@ -36,6 +40,7 @@ import { getSwcLoader } from './utils/loaders/swcLoader';
3640
import { getVariables } from './utils/config';
3741
import { ManifestPlugin } from './utils/plugins/ManifestPlugin';
3842
import { getLatestCommit } from './utils/git';
43+
import { reactCompilerOptions } from './constants';
3944

4045
const buildTypes = loadBuildTypesConfig();
4146
const { args, cacheKey, features } = parseArgv(argv.slice(2), buildTypes);
@@ -307,13 +312,27 @@ const config = {
307312
{
308313
test: /\.(?:ts|mts|tsx)$/u,
309314
exclude: NODE_MODULES_RE,
310-
use: [tsxLoader, codeFenceLoader],
315+
use: [
316+
{
317+
loader: reactCompilerLoader,
318+
options: defineReactCompilerLoaderOption(reactCompilerOptions),
319+
},
320+
tsxLoader,
321+
codeFenceLoader,
322+
],
311323
},
312324
// own javascript, and own javascript with jsx
313325
{
314326
test: /\.(?:js|mjs|jsx)$/u,
315327
exclude: NODE_MODULES_RE,
316-
use: [jsxLoader, codeFenceLoader],
328+
use: [
329+
{
330+
loader: reactCompilerLoader,
331+
options: defineReactCompilerLoaderOption(reactCompilerOptions),
332+
},
333+
jsxLoader,
334+
codeFenceLoader,
335+
],
317336
},
318337
// vendor javascript. We must transform all npm modules to ensure browser
319338
// compatibility.

0 commit comments

Comments
 (0)