Skip to content

Commit c2a56cb

Browse files
gaearonfeiqitian
authored andcommitted
Resolve babel-runtime relative to the config (facebook#535)
This makes generators work with Jest. Fixes facebook#255. Replaces facebook#262.
1 parent 63197c4 commit c2a56cb

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

config/babel.dev.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
var path = require('path');
11+
1012
module.exports = {
1113
// Don't try to find .babelrc because we want to force this configuration.
1214
babelrc: false,
@@ -33,7 +35,10 @@ module.exports = {
3335
[require.resolve('babel-plugin-transform-runtime'), {
3436
helpers: false,
3537
polyfill: false,
36-
regenerator: true
38+
regenerator: true,
39+
// Resolve the Babel runtime relative to the config.
40+
// You can safely remove this after ejecting:
41+
moduleName: path.dirname(require.resolve('babel-runtime/package'))
3742
}]
3843
]
3944
};

config/babel.prod.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
var path = require('path');
11+
1012
module.exports = {
1113
// Don't try to find .babelrc because we want to force this configuration.
1214
babelrc: false,
@@ -30,7 +32,10 @@ module.exports = {
3032
[require.resolve('babel-plugin-transform-runtime'), {
3133
helpers: false,
3234
polyfill: false,
33-
regenerator: true
35+
regenerator: true,
36+
// Resolve the Babel runtime relative to the config.
37+
// You can safely remove this after ejecting:
38+
moduleName: path.dirname(require.resolve('babel-runtime/package'))
3439
}],
3540
// Optimization: hoist JSX that never changes out of render()
3641
// Disabled because of issues:

config/webpack.config.dev.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,8 @@ module.exports = {
6868
// These are the reasonable defaults supported by the Node ecosystem.
6969
extensions: ['.js', '.json', ''],
7070
alias: {
71-
// This `alias` section can be safely removed after ejection.
72-
// We do this because `babel-runtime` may be inside `react-scripts`,
73-
// so when `babel-plugin-transform-runtime` imports it, it will not be
74-
// available to the app directly. This is a temporary solution that lets
75-
// us ship support for generators. However it is far from ideal, and
76-
// if we don't have a good solution, we should just make `babel-runtime`
77-
// a dependency in generated projects.
78-
// See https://github.com/facebookincubator/create-react-app/issues/255
79-
'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator'),
71+
// Support React Native Web
72+
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
8073
'react-native': 'react-native-web'
8174
}
8275
},

config/webpack.config.prod.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,8 @@ module.exports = {
6363
// These are the reasonable defaults supported by the Node ecosystem.
6464
extensions: ['.js', '.json', ''],
6565
alias: {
66-
// This `alias` section can be safely removed after ejection.
67-
// We do this because `babel-runtime` may be inside `react-scripts`,
68-
// so when `babel-plugin-transform-runtime` imports it, it will not be
69-
// available to the app directly. This is a temporary solution that lets
70-
// us ship support for generators. However it is far from ideal, and
71-
// if we don't have a good solution, we should just make `babel-runtime`
72-
// a dependency in generated projects.
73-
// See https://github.com/facebookincubator/create-react-app/issues/255
74-
'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator'),
66+
// Support React Native Web
67+
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
7568
'react-native': 'react-native-web'
7669
}
7770
},

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"babel-plugin-transform-object-rest-spread": "6.8.0",
3838
"babel-plugin-transform-react-constant-elements": "6.9.1",
3939
"babel-plugin-transform-regenerator": "6.14.0",
40-
"babel-plugin-transform-runtime": "6.12.0",
40+
"babel-plugin-transform-runtime": "6.15.0",
4141
"babel-preset-latest": "6.14.0",
4242
"babel-preset-react": "6.11.1",
4343
"babel-runtime": "6.11.6",

0 commit comments

Comments
 (0)