diff --git a/build-scripts/bundle.cjs b/build-scripts/bundle.cjs index c341909b19..e0503a7a73 100644 --- a/build-scripts/bundle.cjs +++ b/build-scripts/bundle.cjs @@ -3,6 +3,8 @@ const env = require("./env.cjs"); const paths = require("./paths.cjs"); const { dependencies } = require("../package.json"); +const BABEL_PLUGINS = path.join(__dirname, "babel-plugins"); + // GitHub base URL to use for production source maps // Nightly builds use the commit SHA, otherwise assumes there is a tag that matches the version module.exports.sourceMapURL = () => { @@ -100,22 +102,12 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({ ], plugins: [ [ - path.resolve( - paths.polymer_dir, - "build-scripts/babel-plugins/inline-constants-plugin.cjs" - ), + path.join(BABEL_PLUGINS, "inline-constants-plugin.cjs"), { modules: ["@mdi/js"], ignoreModuleNotFound: true, }, ], - [ - path.resolve( - paths.polymer_dir, - "build-scripts/babel-plugins/custom-polyfill-plugin.js" - ), - { method: "usage-global" }, - ], // Minify template literals for production isProdBuild && [ "template-html-minifier", @@ -153,6 +145,17 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({ ], sourceMaps: !isTestBuild, overrides: [ + { + // Add plugin to inject various polyfills, excluding the polyfills + // themselves to prevent self- injection. + plugins: [ + [ + path.join(BABEL_PLUGINS, "custom-polyfill-plugin.js"), + { method: "usage-global" }, + ], + ], + exclude: /\/node_modules\/(?:unfetch|proxy-polyfill)\//, + }, { // 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