feat: enable react compiler for @payloadcms/next package (#7839)

also upgrades esbuild and react compiler packages
This commit is contained in:
Alessio Gravili
2024-08-23 14:01:21 -04:00
committed by GitHub
parent 4bbc593dc5
commit 83022f6d55
20 changed files with 309 additions and 208 deletions

View File

@@ -0,0 +1,36 @@
const fs = require('fs')
// Plugin options can be found here: https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts#L38
const ReactCompilerConfig = {
sources: (filename) => {
const isInNodeModules = filename.includes('node_modules')
if (isInNodeModules || ( !filename.endsWith('.tsx') && !filename.endsWith('.jsx') && !filename.endsWith('.js'))) {
return false
}
// Only compile files with 'use client' directives. We do not want to
// accidentally compile React Server Components
const file = fs.readFileSync(filename, 'utf8')
if (file.includes("'use client'")) {
return true
}
console.log('React compiler - skipping file: ' + filename)
return false
},
}
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)$',
},
],*/
],
}
}