mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-24 05:05:53 +08:00
Disable ES2015 transforms based on node version using babel-preset-env (#878)
* Disable ES2015 transforms based on node version using babel-preset-env * pass major version number for node to babel-preset-env instead of version string * use parseFloat() instead of parseInt() to parse node version * fixed style nits
This commit is contained in:
committed by
Dan Abramov
parent
c6428eaff9
commit
351e449ef0
@@ -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: [
|
||||
// ES features necessary for user's Node version
|
||||
[require('babel-preset-env').default, {
|
||||
targets: {
|
||||
node: parseFloat(process.versions.node),
|
||||
},
|
||||
}],
|
||||
// JSX, Flow
|
||||
require.resolve('babel-preset-react')
|
||||
],
|
||||
plugins: plugins
|
||||
};
|
||||
} 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')
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"babel-plugin-transform-react-jsx-source": "6.9.0",
|
||||
"babel-plugin-transform-regenerator": "6.16.1",
|
||||
"babel-plugin-transform-runtime": "6.15.0",
|
||||
"babel-preset-env": "0.0.4",
|
||||
"babel-preset-latest": "6.14.0",
|
||||
"babel-preset-react": "6.11.1",
|
||||
"babel-runtime": "6.11.6"
|
||||
|
||||
Reference in New Issue
Block a user