Skip to content

Commit eb1b921

Browse files
Timergaearon
authored andcommitted
Loosen Babel preset to use browserslist (#3770)
* Provide better defaults * Let babel determine features to compile * meh * Remove setting of BABEL_ENV * Revert "Remove setting of BABEL_ENV" This reverts commit ee2db70. * Set browsers to ie9
1 parent 527fdfe commit eb1b921

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

packages/babel-preset-react-app/index.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ module.exports = function(api, opts) {
4646
// Latest stable ECMAScript features
4747
require('@babel/preset-env').default,
4848
{
49-
targets: {
50-
// React parses on ie 9, so we should too
51-
ie: 9,
52-
},
53-
// We currently minify with uglify
54-
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
55-
forceAllTransforms: true,
56-
// Disable polyfill transforms
57-
useBuiltIns: false,
49+
// `entry` transforms `@babel/polyfill` into individual requires for
50+
// the targeted browsers. This is safer than `usage` which performs
51+
// static code analysis to determine what's required.
52+
// This is probably a fine default to help trim down bundles when
53+
// end-users inevitably import '@babel/polyfill'.
54+
useBuiltIns: 'entry',
5855
// Do not transform modules to CJS
5956
modules: false,
6057
},
@@ -108,7 +105,7 @@ module.exports = function(api, opts) {
108105
!isEnvTest && [
109106
require('@babel/plugin-transform-regenerator').default,
110107
{
111-
// Async functions are converted to generators by babel-preset-env
108+
// Async functions are converted to generators by @babel/preset-env
112109
async: false,
113110
},
114111
],

packages/react-scripts/scripts/init.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ module.exports = function(
4343
eject: 'react-scripts eject',
4444
};
4545

46-
appPackage.browserslist = [
47-
'>1%',
48-
'last 4 versions',
49-
'Firefox ESR',
50-
'not ie < 9',
51-
];
46+
appPackage.browserslist = {
47+
development: ['chrome', 'firefox', 'edge'].map(
48+
browser => `last 2 ${browser} versions`
49+
),
50+
production: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 11'],
51+
};
5252

5353
fs.writeFileSync(
5454
path.join(appPath, 'package.json'),

tasks/e2e-kitchensink.sh

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ original_yarn_registry_url=`yarn config get registry`
2222

2323
function cleanup {
2424
echo 'Cleaning up.'
25+
unset BROWSERSLIST
2526
ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9
2627
cd "$root_path"
2728
# TODO: fix "Device or resource busy" and remove ``|| $CI`
@@ -114,6 +115,9 @@ yarn add test-integrity@^2.0.1
114115
# Enter the app directory
115116
cd "$temp_app_path/test-kitchensink"
116117

118+
# In kitchensink, we want to test all transforms
119+
export BROWSERSLIST='ie 9'
120+
117121
# Link to test module
118122
npm link "$temp_module_path/node_modules/test-integrity"
119123

0 commit comments

Comments
 (0)