@@ -35,18 +35,40 @@ module.exports = {
35
35
// Resolve the Babel runtime relative to the config.
36
36
moduleName : path . dirname ( require . resolve ( 'babel-runtime/package' ) )
37
37
} ]
38
- ] ,
39
- env : {
40
- production : {
41
- plugins : [
42
- // Optimization: hoist JSX that never changes out of render()
43
- // Disabled because of issues:
44
- // * https://github.com/facebookincubator/create-react-app/issues/525
45
- // * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/
46
- // * https://github.com/babel/babel/issues/4516
47
- // TODO: Enable again when these issues are resolved.
48
- // require.resolve('babel-plugin-transform-react-constant-elements')
49
- ]
50
- }
51
- }
38
+ ]
52
39
} ;
40
+
41
+ // This is similar to how `env` works in Babel:
42
+ // https://babeljs.io/docs/usage/babelrc/#env-option
43
+ // We are not using `env` because it’s ignored in versions > babel-core@6.10.4:
44
+ // https://github.com/babel/babel/issues/4539
45
+ // https://github.com/facebookincubator/create-react-app/issues/720
46
+ // It’s also nice that we can enforce `NODE_ENV` being specified.
47
+ var env = process . env . BABEL_ENV || process . env . NODE_ENV ;
48
+ if ( env !== 'development' && env !== 'test' && env !== 'production' ) {
49
+ throw new Error (
50
+ 'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
51
+ '`BABEL_ENV` environment variables. Valid values are "development", ' +
52
+ '"test", and "production". Instead, received: ' + JSON . stringify ( env ) + '.'
53
+ ) ;
54
+ }
55
+ var plugins = module . exports . plugins ;
56
+ if ( env === 'development' || env === 'test' ) {
57
+ plugins . push . apply ( plugins , [
58
+ // Adds component stack to warning messages
59
+ require . resolve ( 'babel-plugin-transform-react-jsx-source' ) ,
60
+ // Adds __self attribute to JSX which React will use for some warnings
61
+ require . resolve ( 'babel-plugin-transform-react-jsx-self' )
62
+ ] ) ;
63
+ }
64
+ if ( env === 'production' ) {
65
+ // Optimization: hoist JSX that never changes out of render()
66
+ // Disabled because of issues:
67
+ // * https://github.com/facebookincubator/create-react-app/issues/525
68
+ // * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/
69
+ // * https://github.com/babel/babel/issues/4516
70
+ // TODO: Enable again when these issues are resolved.
71
+ // plugins.push.apply(plugins, [
72
+ // require.resolve('babel-plugin-transform-react-constant-elements')
73
+ // ]);
74
+ }
0 commit comments