Skip to content

Commit

Permalink
Babel Preset Default: Configure @babel/preset-env preset to respect a…
Browse files Browse the repository at this point in the history
… local Browserslist configuration (#31898)

* Babel Preset Default: Configure @babel/preset-env preset to respect a local Browserslist configuration

* Replace nullish coalescing operator

* Rename variable for clarity

* Update browserslist to 4.16.6

* Clean up package-lock.json

* Update caniuse-lite

* Fix prettier issue

* Update changelog for scripts too
  • Loading branch information
ocean90 committed May 20, 2021
1 parent 298f508 commit 41fdf59
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
23 changes: 12 additions & 11 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"babel-plugin-react-native-platform-specific-extensions": "1.1.1",
"babel-plugin-transform-remove-console": "6.9.4",
"benchmark": "2.1.4",
"browserslist": "4.16.5",
"browserslist": "4.16.6",
"chalk": "4.0.0",
"commander": "4.1.0",
"concurrently": "3.5.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- Configure `@babel/preset-env` preset to respect a local Browserslist configuration.

## 6.0.0 (2021-05-14)

### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-preset-default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ npm install @wordpress/babel-preset-default --save-dev

### Usage

There are a number of methods to configure Babel. See [Babel's Configuration documentation](https://babeljs.io/docs/en/configuration) for more information. To use this preset, simply reference `@wordpress/default` in the `presets` option in your Babel configuration.
There are a number of methods to configure Babel. See [Babel's Configuration documentation](https://babeljs.io/docs/en/configuration) for more information. To use this preset, simply reference `@wordpress/babel-preset-default` in the `presets` option in your Babel configuration.

For example, using `.babelrc`:

```json
{
"presets": [ "@wordpress/default" ]
"presets": [ "@wordpress/babel-preset-default" ]
}
```

Expand Down
11 changes: 10 additions & 1 deletion packages/babel-preset-default/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
const browserslist = require( 'browserslist' );

module.exports = ( api ) => {
let wpBuildOpts = {};
const isWPBuild = ( name ) =>
Expand Down Expand Up @@ -26,8 +31,12 @@ module.exports = ( api ) => {
};
} else {
opts.modules = false;
const localBrowserslistConfig =
browserslist.findConfig( '.' ) || {};
opts.targets = {
browsers: require( '@wordpress/browserslist-config' ),
browsers:
localBrowserslistConfig.defaults ||
require( '@wordpress/browserslist-config' ),
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@wordpress/browserslist-config": "file:../browserslist-config",
"@wordpress/element": "file:../element",
"@wordpress/warning": "file:../warning",
"browserslist": "^4.16.6",
"core-js": "^3.6.4"
},
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fix

- The default Babel configuration has changed to respect a local Browserslist configuration.

## 16.0.0 (2021-05-14)

### Breaking Changes
Expand Down

0 comments on commit 41fdf59

Please sign in to comment.