-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Disable ES2015 transforms based on node version using babel-preset-env #878
Changes from 2 commits
9480e9b
5ee2eb4
abe898c
935c88f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,7 @@ | |
|
||
var path = require('path'); | ||
|
||
module.exports = { | ||
presets: [ | ||
// Latest stable ECMAScript features | ||
require.resolve('babel-preset-latest'), | ||
// JSX, Flow | ||
require.resolve('babel-preset-react') | ||
], | ||
plugins: [ | ||
const plugins = [ | ||
// class { handleClick = () => { } } | ||
require.resolve('babel-plugin-transform-class-properties'), | ||
// { ...todo, completed: true } | ||
|
@@ -35,8 +28,7 @@ module.exports = { | |
// Resolve the Babel runtime relative to the config. | ||
moduleName: path.dirname(require.resolve('babel-runtime/package')) | ||
}] | ||
] | ||
}; | ||
]; | ||
|
||
// This is similar to how `env` works in Babel: | ||
// https://babeljs.io/docs/usage/babelrc/#env-option | ||
|
@@ -52,7 +44,7 @@ if (env !== 'development' && env !== 'test' && env !== 'production') { | |
'"test", and "production". Instead, received: ' + JSON.stringify(env) + '.' | ||
); | ||
} | ||
var plugins = module.exports.plugins; | ||
|
||
if (env === 'development' || env === 'test') { | ||
plugins.push.apply(plugins, [ | ||
// Adds component stack to warning messages | ||
|
@@ -61,14 +53,42 @@ if (env === 'development' || env === 'test') { | |
require.resolve('babel-plugin-transform-react-jsx-self') | ||
]); | ||
} | ||
if (env === 'production') { | ||
// Optimization: hoist JSX that never changes out of render() | ||
// Disabled because of issues: | ||
// * https://github.com/facebookincubator/create-react-app/issues/525 | ||
// * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/ | ||
// * https://github.com/babel/babel/issues/4516 | ||
// TODO: Enable again when these issues are resolved. | ||
// plugins.push.apply(plugins, [ | ||
// require.resolve('babel-plugin-transform-react-constant-elements') | ||
// ]); | ||
|
||
if (env === 'test') { | ||
module.exports = { | ||
presets: [ | ||
[require('babel-preset-env').default, { | ||
"targets": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: quotes are unnecessary here, let's leave just |
||
"node": parseInt(process.versions.node), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
}], | ||
// JSX, Flow | ||
require.resolve('babel-preset-react') | ||
], | ||
plugins: plugins | ||
}; | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: please move } else { |
||
module.exports = { | ||
presets: [ | ||
// Latest stable ECMAScript features | ||
require.resolve('babel-preset-latest'), | ||
// JSX, Flow | ||
require.resolve('babel-preset-react') | ||
], | ||
plugins: plugins | ||
}; | ||
|
||
if (env === 'production') { | ||
// Optimization: hoist JSX that never changes out of render() | ||
// Disabled because of issues: | ||
// * https://github.com/facebookincubator/create-react-app/issues/525 | ||
// * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/ | ||
// * https://github.com/babel/babel/issues/4516 | ||
// TODO: Enable again when these issues are resolved. | ||
// plugins.push.apply(plugins, [ | ||
// require.resolve('babel-plugin-transform-react-constant-elements') | ||
// ]); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment above this line.
Something like
// ES features necessary for user's Node version