Skip to content

Commit

Permalink
Add Babel polyfill provider ES shims
Browse files Browse the repository at this point in the history
Rollup will log a warning for code requiring polyfills:

> (!) Unresolved dependencies
> https://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency
> error-cause/Error (imported by "src/govuk/errors/index.mjs")

Babel will also log a warning:

> Some polyfills have been added but are not present in your dependencies.
>
> Please run one of the following commands:
> 	npm install --save error-cause@^1.0.1
> 	yarn add error-cause@^1.0.1

See ES shims on GitHub: https://github.com/es-shims
  • Loading branch information
colinrotherham committed Oct 31, 2023
1 parent 3ee28c5 commit f84949f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions packages/govuk-frontend/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
module.exports = function (api) {
const isBrowser = !api.env('test')
const isProduction = !api.env('development')

// Apply Browserslist environment for supported targets
// https://github.com/browserslist/browserslist#configuring-for-different-environments
Expand Down Expand Up @@ -33,6 +34,19 @@ module.exports = function (api) {
return !isPrivate && isDocumentation
}
},
plugins: [
[
'polyfill-es-shims',
{
// Add logging for required polyfills
debug: isProduction,

// Replace unsupported code with polyfills
// without modifying window globals
method: 'usage-pure'
}
]
],
presets: [
[
'@babel/preset-env',
Expand Down
1 change: 1 addition & 0 deletions packages/govuk-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"autoprefixer": "^10.4.16",
"babel-plugin-polyfill-es-shims": "^0.10.0",
"cssnano": "^6.0.1",
"cssnano-preset-default": "^6.0.1",
"govuk-prototype-kit": "^13.13.6",
Expand Down

0 comments on commit f84949f

Please sign in to comment.