Skip to content

Commit 70ed774

Browse files
committed
Revert "Revert webpack config"
This reverts commit 8ac83e8.
1 parent 8ac83e8 commit 70ed774

File tree

4 files changed

+178
-4
lines changed

4 files changed

+178
-4
lines changed

development/webpack/utils/config.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { join } from 'node:path';
22
import { readFileSync } from 'node:fs';
33
import { parse } from 'dotenv';
4+
import type { ReactCompilerLoaderOption } from 'react-compiler-webpack';
5+
import type { EnvironmentConfig } from 'babel-plugin-react-compiler';
46
import { setEnvironmentVariables } from '../../build/set-environment-variables';
57
import type { Variables } from '../../lib/variables';
68
import type { BuildTypesConfig, BuildType } from '../../lib/build-type';
@@ -189,3 +191,116 @@ function loadConfigVars(
189191

190192
return definitions;
191193
}
194+
195+
/**
196+
* React Compiler logger that tracks compilation statistics
197+
*/
198+
class ReactCompilerLogger {
199+
private compiledCount = 0;
200+
201+
private skippedCount = 0;
202+
203+
private errorCount = 0;
204+
205+
private compiledFiles: string[] = [];
206+
207+
private skippedFiles: string[] = [];
208+
209+
private errorFiles: string[] = [];
210+
211+
logEvent(filename: string | null, event: { kind: string; reason?: string }) {
212+
if (filename === null) {
213+
return;
214+
}
215+
switch (event.kind) {
216+
case 'CompileSuccess':
217+
this.compiledCount++;
218+
this.compiledFiles.push(filename);
219+
// console.log(`✅ Compiled: ${filename}`);
220+
break;
221+
case 'CompileSkip':
222+
this.skippedCount++;
223+
this.skippedFiles.push(filename);
224+
break;
225+
case 'CompileError':
226+
this.errorCount++;
227+
this.errorFiles.push(filename);
228+
// console.error(
229+
// `❌ React Compiler error in ${filename}: ${event.reason || 'Unknown error'}`,
230+
// );
231+
break;
232+
default:
233+
// Ignore other event types
234+
break;
235+
}
236+
}
237+
238+
getStats() {
239+
return {
240+
compiled: this.compiledCount,
241+
skipped: this.skippedCount,
242+
errors: this.errorCount,
243+
total: this.compiledCount + this.skippedCount + this.errorCount,
244+
compiledFiles: this.compiledFiles,
245+
skippedFiles: this.skippedFiles,
246+
errorFiles: this.errorFiles,
247+
};
248+
}
249+
250+
logSummary() {
251+
const stats = this.getStats();
252+
console.log('\n📊 React Compiler Statistics:');
253+
console.log(` ✅ Compiled: ${stats.compiled} files`);
254+
console.log(` ⏭️ Skipped: ${stats.skipped} files`);
255+
console.log(` ❌ Errors: ${stats.errors} files`);
256+
console.log(` 📦 Total processed: ${stats.total} files`);
257+
}
258+
}
259+
260+
// Create a singleton logger instance
261+
const reactCompilerLogger = new ReactCompilerLogger();
262+
263+
export const reactCompilerOptions = {
264+
target: '17',
265+
logger: reactCompilerLogger,
266+
gating: null,
267+
noEmit: false,
268+
compilationMode: 'all',
269+
eslintSuppressionRules: null,
270+
flowSuppressions: false,
271+
ignoreUseNoForget: false,
272+
sources: (filename) => {
273+
if (!filename.includes('/ui/')) {
274+
return false;
275+
}
276+
const excludePatterns = [
277+
'.test.',
278+
'.stories.',
279+
'.container.',
280+
'/__mocks__/',
281+
'/__snapshots__/',
282+
'/constants/',
283+
'/helpers/',
284+
'/ducks/',
285+
'/selectors/',
286+
'/store/',
287+
'/component-library/',
288+
];
289+
if (excludePatterns.some((pattern) => filename.includes(pattern))) {
290+
return false;
291+
}
292+
return true;
293+
},
294+
enableReanimatedCheck: false,
295+
environment: {} as EnvironmentConfig,
296+
dynamicGating: null,
297+
panicThreshold: 'none',
298+
customOptOutDirectives: null,
299+
} as const satisfies ReactCompilerLoaderOption;
300+
301+
/**
302+
* Get the React Compiler logger instance for accessing statistics
303+
*/
304+
export function getReactCompilerLogger(): ReactCompilerLogger {
305+
return reactCompilerLogger;
306+
}

development/webpack/webpack.config.ts

Lines changed: 36 additions & 3 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 {
@@ -33,7 +37,11 @@ import { transformManifest } from './utils/plugins/ManifestPlugin/helpers';
3337
import { parseArgv, getDryRunMessage } from './utils/cli';
3438
import { getCodeFenceLoader } from './utils/loaders/codeFenceLoader';
3539
import { getSwcLoader } from './utils/loaders/swcLoader';
36-
import { getVariables } from './utils/config';
40+
import {
41+
getVariables,
42+
reactCompilerOptions,
43+
getReactCompilerLogger,
44+
} from './utils/config';
3745
import { ManifestPlugin } from './utils/plugins/ManifestPlugin';
3846
import { getLatestCommit } from './utils/git';
3947

@@ -210,6 +218,17 @@ if (args.progress) {
210218
const { ProgressPlugin } = require('webpack');
211219
plugins.push(new ProgressPlugin());
212220
}
221+
222+
// React Compiler statistics logger plugin
223+
plugins.push({
224+
apply(compiler) {
225+
compiler.hooks.done.tap('ReactCompilerStatsPlugin', () => {
226+
const logger = getReactCompilerLogger();
227+
logger.logSummary();
228+
});
229+
},
230+
} as WebpackPluginInstance);
231+
213232
// #endregion plugins
214233

215234
const swcConfig = { args, browsersListQuery, isDevelopment };
@@ -323,13 +342,27 @@ const config = {
323342
{
324343
test: /\.(?:ts|mts|tsx)$/u,
325344
exclude: NODE_MODULES_RE,
326-
use: [tsxLoader, codeFenceLoader],
345+
use: [
346+
{
347+
loader: reactCompilerLoader,
348+
options: defineReactCompilerLoaderOption(reactCompilerOptions),
349+
},
350+
tsxLoader,
351+
codeFenceLoader,
352+
],
327353
},
328354
// own javascript, and own javascript with jsx
329355
{
330356
test: /\.(?:js|mjs|jsx)$/u,
331357
exclude: NODE_MODULES_RE,
332-
use: [jsxLoader, codeFenceLoader],
358+
use: [
359+
{
360+
loader: reactCompilerLoader,
361+
options: defineReactCompilerLoaderOption(reactCompilerOptions),
362+
},
363+
jsxLoader,
364+
codeFenceLoader,
365+
],
333366
},
334367
// vendor javascript. We must transform all npm modules to ensure browser
335368
// compatibility.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@
682682
"process": "^0.11.10",
683683
"pumpify": "^2.0.1",
684684
"randomcolor": "^0.5.4",
685+
"react-compiler-webpack": "0.2.1",
685686
"react-devtools": "^6.1.5",
686687
"react-devtools-core": "^6.1.5",
687688
"react-syntax-highlighter": "^15.5.0",

yarn.lock

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ __metadata:
834834
languageName: node
835835
linkType: hard
836836

837-
"@babel/plugin-syntax-jsx@npm:^7.22.5, @babel/plugin-syntax-jsx@npm:^7.25.9, @babel/plugin-syntax-jsx@npm:^7.7.2":
837+
"@babel/plugin-syntax-jsx@npm:^7.22.5, @babel/plugin-syntax-jsx@npm:^7.25.9, @babel/plugin-syntax-jsx@npm:^7.27.1, @babel/plugin-syntax-jsx@npm:^7.7.2":
838838
version: 7.27.1
839839
resolution: "@babel/plugin-syntax-jsx@npm:7.27.1"
840840
dependencies:
@@ -933,6 +933,17 @@ __metadata:
933933
languageName: node
934934
linkType: hard
935935

936+
"@babel/plugin-syntax-typescript@npm:^7.27.1":
937+
version: 7.27.1
938+
resolution: "@babel/plugin-syntax-typescript@npm:7.27.1"
939+
dependencies:
940+
"@babel/helper-plugin-utils": "npm:^7.27.1"
941+
peerDependencies:
942+
"@babel/core": ^7.0.0-0
943+
checksum: 10/87836f7e32af624c2914c73cd6b9803cf324e07d43f61dbb973c6a86f75df725e12540d91fac7141c14b697aa9268fd064220998daced156e96ac3062d7afb41
944+
languageName: node
945+
linkType: hard
946+
936947
"@babel/plugin-syntax-unicode-sets-regex@npm:^7.18.6":
937948
version: 7.18.6
938949
resolution: "@babel/plugin-syntax-unicode-sets-regex@npm:7.18.6"
@@ -33485,6 +33496,7 @@ __metadata:
3348533496
react-beautiful-dnd: "npm:^13.1.1"
3348633497
react-chartjs-2: "npm:^5.2.0"
3348733498
react-compiler-runtime: "npm:19.1.0-rc.3"
33499+
react-compiler-webpack: "npm:0.2.1"
3348833500
react-devtools: "npm:^6.1.5"
3348933501
react-devtools-core: "npm:^6.1.5"
3349033502
react-dom: "npm:^17.0.2"
@@ -37649,6 +37661,19 @@ __metadata:
3764937661
languageName: node
3765037662
linkType: hard
3765137663

37664+
"react-compiler-webpack@npm:0.2.1":
37665+
version: 0.2.1
37666+
resolution: "react-compiler-webpack@npm:0.2.1"
37667+
dependencies:
37668+
"@babel/core": "npm:^7.28.4"
37669+
"@babel/plugin-syntax-jsx": "npm:^7.27.1"
37670+
"@babel/plugin-syntax-typescript": "npm:^7.27.1"
37671+
peerDependencies:
37672+
babel-plugin-react-compiler: "*"
37673+
checksum: 10/5571abebe68334969f3a40c6c21a4a6c3d8ba8a63c91348eac1209624e58e5b373609677244bbbd7480a094517c1b15f75d54400a91914728d74c9194d76775a
37674+
languageName: node
37675+
linkType: hard
37676+
3765237677
"react-devtools-core@npm:6.1.5, react-devtools-core@npm:^6.1.5":
3765337678
version: 6.1.5
3765437679
resolution: "react-devtools-core@npm:6.1.5"

0 commit comments

Comments
 (0)