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) {