From b1522e9a32eef6884dce6f19174c84808619651a Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Sun, 19 Nov 2023 18:41:23 +0000 Subject: [PATCH] Fix Babel runtime helper injections --- build-scripts/bundle.cjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build-scripts/bundle.cjs b/build-scripts/bundle.cjs index e662941010bb..684e5aa45a8c 100644 --- a/build-scripts/bundle.cjs +++ b/build-scripts/bundle.cjs @@ -87,8 +87,6 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({ setSpreadProperties: true, }, browserslistEnv: latestBuild ? "modern" : "legacy", - // Must be unambiguous because some dependencies are CommonJS only - sourceType: "unambiguous", presets: [ [ "@babel/preset-env", @@ -143,6 +141,18 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({ /node_modules[\\/]webpack[\\/]buildin/, ], sourceMaps: !isTestBuild, + overrides: [ + { + // Use unambiguous for dependencies so that require() is correctly injected into CommonJS files + // Exclusions are needed in some cases where ES modules have no static imports or exports, such as polyfills + sourceType: "unambiguous", + include: /\/node_modules\//, + exclude: [ + "element-internals-polyfill", + "@?lit(?:-labs|-element|-html)?", + ].map((p) => new RegExp(`/node_modules/${p}/`)), + }, + ], }); const nameSuffix = (latestBuild) => (latestBuild ? "-modern" : "-legacy");