From c1f041649f6c8815fd57c127e1e622d330038492 Mon Sep 17 00:00:00 2001 From: Vlad Fedosov Date: Fri, 17 May 2024 17:44:57 -0400 Subject: [PATCH] fix(lexical): #6132 react build size regression from #6088 (#6133) --- scripts/build.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 18a8c5681c9..41b8d0ffed6 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -94,13 +94,11 @@ function resolveExternalEsm(id) { * party dependencies or peerDependencies that we do not want to include * in the bundles. */ -const externals = [ - ...Object.entries(wwwMappings).flat(), - 'react-dom', - 'react', - 'yjs', - 'y-websocket', -].sort(); +const monorepoExternalsSet = new Set(Object.entries(wwwMappings).flat()); +const thirdPartyExternals = ['react', 'react-dom', 'yjs', 'y-websocket']; +const thirdPartyExternalsRegExp = new RegExp( + `^(${thirdPartyExternals.join('|')})(\\/|$)`, +); const strictWWWMappings = {}; @@ -131,7 +129,10 @@ async function build(name, inputFile, outputPath, outputFile, isProd, format) { const extensions = ['.js', '.jsx', '.ts', '.tsx']; const inputOptions = { external(modulePath, src) { - return externals.includes(modulePath); + return ( + monorepoExternalsSet.has(modulePath) || + thirdPartyExternalsRegExp.test(modulePath) + ); }, input: inputFile, onwarn(warning) {