-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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 Babel 7 #3522
Switch to Babel 7 #3522
Changes from 30 commits
7a07a1a
7cbeb83
b0ba884
5cb193c
ae2b569
222a905
f9391f7
fbaacf4
0cdf4f9
dc15217
60a42ae
911debc
8003d54
c180b49
eff7257
ca7516d
482abf2
539e46a
60a5f57
67ca211
60ab887
95dbd6f
dea535e
1466478
ab26521
fb6480d
f95e5a9
7f29d27
44d93ab
b81c25f
174ddf5
9f504c2
4ade5c3
9537092
a29c74d
effe64a
0d5043d
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 |
---|---|---|
|
@@ -6,134 +6,113 @@ | |
*/ | ||
'use strict'; | ||
|
||
const plugins = [ | ||
// Experimental macros support. Will be documented after it's had some time | ||
// in the wild. | ||
require.resolve('babel-plugin-macros'), | ||
// class { handleClick = () => { } } | ||
require.resolve('babel-plugin-transform-class-properties'), | ||
// The following two plugins use Object.assign directly, instead of Babel's | ||
// extends helper. Note that this assumes `Object.assign` is available. | ||
// { ...todo, completed: true } | ||
[ | ||
require.resolve('babel-plugin-transform-object-rest-spread'), | ||
{ | ||
useBuiltIns: true, | ||
}, | ||
], | ||
// Transforms JSX | ||
[ | ||
require.resolve('babel-plugin-transform-react-jsx'), | ||
{ | ||
useBuiltIns: true, | ||
}, | ||
], | ||
// Polyfills the runtime needed for async/await and generators | ||
[ | ||
require.resolve('babel-plugin-transform-runtime'), | ||
{ | ||
helpers: false, | ||
polyfill: false, | ||
regenerator: true, | ||
}, | ||
], | ||
]; | ||
|
||
// This is similar to how `env` works in Babel: | ||
// https://babeljs.io/docs/usage/babelrc/#env-option | ||
// We are not using `env` because it’s ignored in versions > [email protected]: | ||
// https://github.com/babel/babel/issues/4539 | ||
// https://github.com/facebookincubator/create-react-app/issues/720 | ||
// It’s also nice that we can enforce `NODE_ENV` being specified. | ||
var env = process.env.BABEL_ENV || process.env.NODE_ENV; | ||
if (env !== 'development' && env !== 'test' && env !== 'production') { | ||
throw new Error( | ||
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' + | ||
'`BABEL_ENV` environment variables. Valid values are "development", ' + | ||
'"test", and "production". Instead, received: ' + | ||
JSON.stringify(env) + | ||
'.' | ||
); | ||
} | ||
module.exports = function(api, opts) { | ||
if (!opts) { | ||
opts = {}; | ||
} | ||
|
||
if (env === 'development' || env === 'test') { | ||
// The following two plugins are currently necessary to make React warnings | ||
// include more valuable information. They are included here because they are | ||
// currently not enabled in babel-preset-react. See the below threads for more info: | ||
// https://github.com/babel/babel/issues/4702 | ||
// https://github.com/babel/babel/pull/3540#issuecomment-228673661 | ||
// https://github.com/facebookincubator/create-react-app/issues/989 | ||
plugins.push.apply(plugins, [ | ||
// Adds component stack to warning messages | ||
require.resolve('babel-plugin-transform-react-jsx-source'), | ||
// Adds __self attribute to JSX which React will use for some warnings | ||
require.resolve('babel-plugin-transform-react-jsx-self'), | ||
]); | ||
} | ||
// This is similar to how `env` works in Babel: | ||
// https://babeljs.io/docs/usage/babelrc/#env-option | ||
// We are not using `env` because it’s ignored in versions > [email protected]: | ||
// https://github.com/babel/babel/issues/4539 | ||
// https://github.com/facebookincubator/create-react-app/issues/720 | ||
// It’s also nice that we can enforce `NODE_ENV` being specified. | ||
var env = process.env.BABEL_ENV || process.env.NODE_ENV; | ||
var isEnvDevelopment = env === 'development'; | ||
var isEnvProduction = env === 'production'; | ||
var isEnvTest = env === 'test'; | ||
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) { | ||
throw new Error( | ||
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' + | ||
'`BABEL_ENV` environment variables. Valid values are "development", ' + | ||
'"test", and "production". Instead, received: ' + | ||
JSON.stringify(env) + | ||
'.' | ||
); | ||
} | ||
|
||
if (env === 'test') { | ||
module.exports = { | ||
return { | ||
presets: [ | ||
// ES features necessary for user's Node version | ||
[ | ||
require('babel-preset-env').default, | ||
isEnvTest && [ | ||
// ES features necessary for user's Node version | ||
require('@babel/preset-env').default, | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
// JSX, Flow | ||
require.resolve('babel-preset-react'), | ||
], | ||
plugins: plugins.concat([ | ||
// Compiles import() to a deferred require() | ||
require.resolve('babel-plugin-dynamic-import-node'), | ||
]), | ||
}; | ||
} else { | ||
module.exports = { | ||
presets: [ | ||
// Latest stable ECMAScript features | ||
[ | ||
require.resolve('babel-preset-env'), | ||
(isEnvProduction || isEnvDevelopment) && [ | ||
// Latest stable ECMAScript features | ||
require('@babel/preset-env').default, | ||
{ | ||
targets: { | ||
// React parses on ie 9, so we should too | ||
ie: 9, | ||
// We currently minify with uglify | ||
// Remove after https://github.com/mishoo/UglifyJS2/issues/448 | ||
uglify: true, | ||
}, | ||
// We currently minify with uglify | ||
// Remove after https://github.com/mishoo/UglifyJS2/issues/448 | ||
forceAllTransforms: true, | ||
// Disable polyfill transforms | ||
useBuiltIns: false, | ||
// Do not transform modules to CJS | ||
modules: false, | ||
}, | ||
], | ||
// JSX, Flow | ||
require.resolve('babel-preset-react'), | ||
], | ||
plugins: plugins.concat([ | ||
// function* () { yield 42; yield 43; } | ||
[ | ||
require.resolve('babel-plugin-transform-regenerator'), | ||
require('@babel/preset-react').default, | ||
{ | ||
// Adds component stack to warning messages | ||
// Adds __self attribute to JSX which React will use for some warnings | ||
development: isEnvDevelopment || isEnvTest, | ||
}, | ||
], | ||
[require('@babel/preset-flow').default], | ||
].filter(Boolean), | ||
plugins: [ | ||
// Experimental macros support. Will be documented after it's had some time | ||
// in the wild. | ||
require('babel-plugin-macros'), | ||
// class { handleClick = () => { } } | ||
require('@babel/plugin-proposal-class-properties').default, | ||
// The following two plugins use Object.assign directly, instead of Babel's | ||
// extends helper. Note that this assumes `Object.assign` is available. | ||
// { ...todo, completed: true } | ||
[ | ||
require('@babel/plugin-proposal-object-rest-spread').default, | ||
{ | ||
useBuiltIns: true, | ||
}, | ||
], | ||
// Transforms JSX | ||
[ | ||
require('@babel/plugin-transform-react-jsx').default, | ||
{ | ||
useBuiltIns: true, | ||
}, | ||
], | ||
// Polyfills the runtime needed for async/await and generators | ||
[ | ||
require('@babel/plugin-transform-runtime').default, | ||
{ | ||
helpers: false, | ||
polyfill: false, | ||
regenerator: true, | ||
}, | ||
], | ||
// function* () { yield 42; yield 43; } | ||
!isEnvTest && [ | ||
require('@babel/plugin-transform-regenerator').default, | ||
{ | ||
// Async functions are converted to generators by babel-preset-env | ||
async: false, | ||
}, | ||
], | ||
// Adds syntax support for import() | ||
require.resolve('babel-plugin-syntax-dynamic-import'), | ||
]), | ||
require('@babel/plugin-syntax-dynamic-import').default, | ||
isEnvTest && | ||
// Transform dynamic import to require | ||
require('babel-plugin-transform-dynamic-import').default, | ||
].filter(Boolean), | ||
}; | ||
|
||
if (env === 'production') { | ||
// Optimization: hoist JSX that never changes out of render() | ||
// Disabled because of issues: https://github.com/facebookincubator/create-react-app/issues/553 | ||
// TODO: Enable again when these issues are resolved. | ||
// plugins.push.apply(plugins, [ | ||
// require.resolve('babel-plugin-transform-react-constant-elements') | ||
// ]); | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,24 @@ module.exports = { | |
rules: [ | ||
{ | ||
test: /\.js$/, | ||
include: path.resolve(__dirname, './src'), | ||
include: [ | ||
path.resolve(__dirname, './src'), | ||
path.dirname( | ||
require.resolve('chalk', { | ||
paths: path.dirname(require.resolve('@babel/code-frame')), | ||
}) | ||
), | ||
path.dirname( | ||
require.resolve( | ||
'ansi-styles', | ||
path.dirname( | ||
require.resolve('chalk', { | ||
paths: path.dirname(require.resolve('@babel/code-frame')), | ||
}) | ||
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. All of this looks very fragile, why did we add it? 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. Oh, okay. #3522 (comment) sigh 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. It should be pretty reliable -- it resolves Same for Alternatively, we can just always compile those modules. |
||
) | ||
) | ||
), | ||
], | ||
use: 'babel-loader', | ||
}, | ||
], | ||
|
This file was deleted.
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.
You might want to use
import { codeFrameColumns } from '@babel/code-frame';
, see https://www.npmjs.com/package/@babel/code-frame#upgrading-from-prior-versions