Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to preset-env #1742

Merged
merged 3 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/babel-preset-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ if (env === 'test') {
module.exports = {
presets: [
// Latest stable ECMAScript features
[require.resolve('babel-preset-latest'), {
'es2015': {
modules: false
}
[require.resolve('babel-preset-env'), {
targets: {
// We support everything React supports
'ie': 9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is enough to match latest behavior? How did you verify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually checked the plugins by hand, and there is a subtle difference.

Latest includes transform-es2015-duplicate-keys, Env does not.
Env includes babel-plugin-check-es2015-constants, latest does not.

This does result in slightly different code:

In:

var obj = {
  a: 1,
  a: 5
}

env:

"use strict";

var obj = {
  a: 1,
  a: 5
};

latest:

"use strict";

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var obj = _defineProperty({
  a: 1
}, "a", 5);

I'm not sure which is proper behavior, but I assume there was a reason for this.
/cc @hzoo @existentialism

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we missed it in our plugin mapping, will fix!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: maybe just ie without quotes?
Also, should we add uglify: true? It's also our baseline target.

Copy link
Contributor Author

@Timer Timer Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure ie 9 covers all that uglify doesn't support, but we can add it for redundancy.

Uglify was only added for people targeting e.g. last 2 versions, >2%.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand but it's good to leave on for people who get excited and immediately override this after ejecting. 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait it's in a preset. I guess it doesn't matter that much then.

},
// Disable polyfill transforms
useBuiltIns: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Contributor Author

@Timer Timer Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is disabled by default but I explicitly set it false so it doesn't accidentally get enabled in a minor release.

Setting this to true requires npm 3 (or node 6) and transforms import "babel-polyfill"; into, e.g. (based on the target):

import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
...

Copy link
Contributor

@existentialism existentialism Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling it will transform import babel-polyfill into only the necessary polyfills and enables the transforms needed, based on targets you specify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@existentialism correct me if I'm wrong but we can't enable this until we drop npm 2.x or node 4 support, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should work... we aren't going to drop node < 4 until 2.x lands.

}],
// JSX, Flow
require.resolve('babel-preset-react')
Expand Down
17 changes: 8 additions & 9 deletions packages/babel-preset-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
"dependencies": {
"babel-plugin-dynamic-import-node": "1.0.0",
"babel-plugin-syntax-dynamic-import": "6.18.0",
"babel-plugin-transform-class-properties": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.22.0",
"babel-plugin-transform-react-constant-elements": "6.22.0",
"babel-plugin-transform-react-jsx": "6.22.0",
"babel-plugin-transform-class-properties": "6.23.0",
"babel-plugin-transform-object-rest-spread": "6.23.0",
"babel-plugin-transform-react-constant-elements": "6.23.0",
"babel-plugin-transform-react-jsx": "6.23.0",
"babel-plugin-transform-react-jsx-self": "6.22.0",
"babel-plugin-transform-react-jsx-source": "6.22.0",
"babel-plugin-transform-regenerator": "6.22.0",
"babel-plugin-transform-runtime": "6.22.0",
"babel-preset-env": "1.1.8",
"babel-preset-latest": "6.22.0",
"babel-preset-react": "6.22.0",
"babel-runtime": "6.22.0"
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.2.1",
"babel-preset-react": "6.23.0",
"babel-runtime": "6.23.0"
}
}