Skip to content

Commit

Permalink
build: react compiler with rspack
Browse files Browse the repository at this point in the history
  • Loading branch information
apostolos committed Sep 6, 2024
1 parent 8cc1d56 commit fa21732
Show file tree
Hide file tree
Showing 4 changed files with 3,386 additions and 4,870 deletions.
76 changes: 11 additions & 65 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
'use strict';
const PRODUCTION = process.env.NODE_ENV === 'production';
// https://web.dev/publish-modern-javascript/
// https://jakearchibald.com/2017/es-modules-in-browsers/
// const MODERN = process.env.MODERN === 'true';
const DEV = !PRODUCTION;
const ReactCompilerConfig = {
// compilationMode: 'annotation',
};

const config = {
browserslistEnv: PRODUCTION ? 'production' : 'development',
parserOpts: {
strictMode: true,
},
assumptions: {
// arrayLikeIsIterable: true,
constantReexports: true,
constantSuper: true,
enumerableModuleMeta: true,
ignoreFunctionLength: true,
ignoreToPrimitiveHint: true,
iterableIsArray: true,
mutableTemplateObject: true,
noClassCalls: true,
noDocumentAll: true,
noNewArrows: true,
objectRestNoSymbols: true,
privateFieldsAsProperties: true,
pureGetters: true,
setClassMethods: true,
setComputedProperties: true,
setPublicClassFields: true,
setSpreadProperties: true,
skipForOfIteratorClosing: true,
superIsCallableConstructor: true,
},
presets: [
[
'@babel/preset-typescript',
{
allowDeclareFields: true, // TODO: Remove in Babel@8+ (it will be the default)
onlyRemoveTypeImports: true,
},
module.exports = function (api) {
api.cache(true);
return {
plugins: [
['babel-plugin-react-compiler', ReactCompilerConfig],
'@babel/plugin-syntax-jsx',
['@babel/plugin-syntax-typescript', { isTSX: true }],
],
['@babel/preset-react', { runtime: 'automatic', development: DEV }],
],
plugins: ['babel-plugin-react-compiler'],
};
};

if (DEV) {
config.plugins.unshift('react-refresh/babel');
} else if (PRODUCTION) {
config.presets.push([
'@babel/env',
{
bugfixes: true, // TODO: Remove in Babel@8+ (it will be the default)
},
]);

config.plugins.push([
'polyfill-corejs3',
{
method: 'usage-global',
version: '3.30.2',
proposals: true,
},
]);
}

module.exports = config;
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
"devDependencies": {
"@aws-sdk/client-cloudfront": "3.645.0",
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.4",
"@babel/preset-react": "7.24.7",
"@babel/preset-typescript": "7.24.7",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
"@babel/plugin-syntax-jsx": "7.24.7",
"@babel/plugin-syntax-typescript": "7.25.4",
"@radix-ui/react-compose-refs": "1.1.0",
"@react-aria/overlays": "3.23.2",
"@rspack/cli": "1.0.3",
Expand All @@ -60,7 +58,6 @@
"@typescript-eslint/parser": "8.4.0",
"autoprefixer": "10.4.20",
"babel-loader": "9.1.3",
"babel-plugin-polyfill-corejs3": "0.10.6",
"babel-plugin-react-compiler": "0.0.0-experimental-7449567-20240904",
"chalk": "5.3.0",
"cli-table": "0.3.11",
Expand Down
Loading

0 comments on commit fa21732

Please sign in to comment.