Skip to content

Commit 84b436c

Browse files
steverepballoobjoostlek
authored
Fix self-injection for custom polyfills (home-assistant#20718)
* Fix self-injection for custom polyfills * Update build-scripts/bundle.cjs Co-authored-by: Joost Lekkerkerker <[email protected]> --------- Co-authored-by: Paulus Schoutsen <[email protected]> Co-authored-by: Joost Lekkerkerker <[email protected]>
1 parent 1925a47 commit 84b436c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

build-scripts/bundle.cjs

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const env = require("./env.cjs");
33
const paths = require("./paths.cjs");
44
const { dependencies } = require("../package.json");
55

6+
const BABEL_PLUGINS = path.join(__dirname, "babel-plugins");
7+
68
// GitHub base URL to use for production source maps
79
// Nightly builds use the commit SHA, otherwise assumes there is a tag that matches the version
810
module.exports.sourceMapURL = () => {
@@ -100,22 +102,12 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({
100102
],
101103
plugins: [
102104
[
103-
path.resolve(
104-
paths.polymer_dir,
105-
"build-scripts/babel-plugins/inline-constants-plugin.cjs"
106-
),
105+
path.join(BABEL_PLUGINS, "inline-constants-plugin.cjs"),
107106
{
108107
modules: ["@mdi/js"],
109108
ignoreModuleNotFound: true,
110109
},
111110
],
112-
[
113-
path.resolve(
114-
paths.polymer_dir,
115-
"build-scripts/babel-plugins/custom-polyfill-plugin.js"
116-
),
117-
{ method: "usage-global" },
118-
],
119111
// Minify template literals for production
120112
isProdBuild && [
121113
"template-html-minifier",
@@ -153,6 +145,17 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({
153145
],
154146
sourceMaps: !isTestBuild,
155147
overrides: [
148+
{
149+
// Add plugin to inject various polyfills, excluding the polyfills
150+
// themselves to prevent self- injection.
151+
plugins: [
152+
[
153+
path.join(BABEL_PLUGINS, "custom-polyfill-plugin.js"),
154+
{ method: "usage-global" },
155+
],
156+
],
157+
exclude: /\/node_modules\/(?:unfetch|proxy-polyfill)\//,
158+
},
156159
{
157160
// Use unambiguous for dependencies so that require() is correctly injected into CommonJS files
158161
// Exclusions are needed in some cases where ES modules have no static imports or exports, such as polyfills

0 commit comments

Comments
 (0)