Skip to content

Commit e97aa1c

Browse files
gaearonGeorge Czabania
authored and
George Czabania
committed
Resolve babel-runtime relative to the config (facebook#535)
This makes generators work with Jest. Fixes facebook#255. Replaces facebook#262.
1 parent 11a4e17 commit e97aa1c

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

config/babel.dev.js

Lines changed: 6 additions & 1 deletion
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

Lines changed: 6 additions & 1 deletion
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

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

config/webpack.config.prod.js

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

package.json

Lines changed: 1 addition & 1 deletion
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)