Skip to content

Commit

Permalink
feat: compile ui using react compiler, using babel
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed May 23, 2024
1 parent fd02bee commit 58f2a29
Show file tree
Hide file tree
Showing 6 changed files with 1,457 additions and 187 deletions.
2 changes: 1 addition & 1 deletion packages/next/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"development": false,
"useBuiltins": true
}
}
},
"experimental": {
"plugins": [
[
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> 1%
not dead
9 changes: 0 additions & 9 deletions packages/ui/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
"tsx": true,
"dts": true
},
"transform": {
"react": {
"runtime": "automatic",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": true
}
}
"experimental": {
"plugins": [
[
Expand Down
44 changes: 44 additions & 0 deletions packages/ui/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const ReactCompilerConfig = {
/*sources: (filename) => {
if(filename.indexOf('src/providers') !== -1) {
console.log('Babl.', filename)
return true
}
return false
},*/
//runtimeModule: "react"
}

module.exports = function (api) {
api.cache(false);

return {
plugins: [
['babel-plugin-react-compiler', ReactCompilerConfig], // must run first!
[
'babel-plugin-transform-remove-imports',
{
test: '\\.(scss|css)$',
},
],
],
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage',
corejs: '3.22',
},
],
[
'@babel/preset-react',
{
throwIfNamespace: false,
runtime: 'automatic',
},
],
'@babel/preset-typescript',
],
}
}
11 changes: 10 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@
],
"scripts": {
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
"build:babel": "babel src --out-dir /Users/alessio/Documents/GitHub/payload-3.0-alpha-demo/node_modules/@payloadcms/ui/dist --source-maps --extensions .ts,.js,.tsx,.jsx,.cjs,.mjs",
"build:reactcompiler": "pnpm copyfiles && pnpm build:babel && pnpm build:types",
"build:remove-artifact": "rm dist/prod/index.js",
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
"build:swc": "swc ./src -d /Users/alessio/Documents/GitHub/payload-3.0-alpha-demo/node_modules/@payloadcms/ui/dist --config-file .swcrc",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"build:webpack": "webpack --config webpack.config.js",
"clean": "rimraf {dist,*.tsbuildinfo}",
Expand Down Expand Up @@ -116,13 +118,20 @@
"uuid": "9.0.1"
},
"devDependencies": {
"@babel/cli": "^7.24.5",
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@payloadcms/eslint-config": "workspace:*",
"@types/body-scroll-lock": "^3.1.0",
"@types/qs": "6.9.7",
"@types/react": "npm:[email protected]",
"@types/react-datepicker": "6.2.0",
"@types/react-dom": "npm:[email protected]",
"@types/uuid": "8.3.4",
"babel-plugin-react-compiler": "0.0.0-experimental-592953e-20240517",
"babel-plugin-transform-remove-imports": "^1.7.1",
"css-loader": "^6.10.0",
"css-minimizer-webpack-plugin": "^6.0.0",
"mini-css-extract-plugin": "1.6.2",
Expand Down
Loading

0 comments on commit 58f2a29

Please sign in to comment.