6
6
*/
7
7
'use strict' ;
8
8
9
- const plugins = [
10
- // Necessary to include regardless of the environment because
11
- // in practice some other transforms (such as object-rest-spread)
12
- // don't work without it: https://github.com/babel/babel/issues/7215
13
- require . resolve ( 'babel-plugin-transform-es2015-destructuring' ) ,
14
- // class { handleClick = () => { } }
15
- require . resolve ( 'babel-plugin-transform-class-properties' ) ,
16
- // The following two plugins use Object.assign directly, instead of Babel's
17
- // extends helper. Note that this assumes `Object.assign` is available.
18
- // { ...todo, completed: true }
19
- [
20
- require . resolve ( 'babel-plugin-transform-object-rest-spread' ) ,
21
- {
22
- useBuiltIns : true ,
23
- } ,
24
- ] ,
25
- // Transforms JSX
26
- [
27
- require . resolve ( 'babel-plugin-transform-react-jsx' ) ,
28
- {
29
- useBuiltIns : true ,
30
- } ,
31
- ] ,
32
- // Polyfills the runtime needed for async/await and generators
33
- [
34
- require . resolve ( 'babel-plugin-transform-runtime' ) ,
35
- {
36
- helpers : false ,
37
- polyfill : false ,
38
- regenerator : true ,
39
- } ,
40
- ] ,
41
- ] ;
9
+ const create = require ( './create' ) ;
42
10
43
11
// This is similar to how `env` works in Babel:
44
12
// https://babeljs.io/docs/usage/babelrc/#env-option
@@ -47,94 +15,5 @@ const plugins = [
47
15
// https://github.com/facebookincubator/create-react-app/issues/720
48
16
// It’s also nice that we can enforce `NODE_ENV` being specified.
49
17
var env = process . env . BABEL_ENV || process . env . NODE_ENV ;
50
- if ( env !== 'development' && env !== 'test' && env !== 'production' ) {
51
- throw new Error (
52
- 'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
53
- '`BABEL_ENV` environment variables. Valid values are "development", ' +
54
- '"test", and "production". Instead, received: ' +
55
- JSON . stringify ( env ) +
56
- '.'
57
- ) ;
58
- }
59
18
60
- if ( env === 'development' || env === 'test' ) {
61
- // The following two plugins are currently necessary to make React warnings
62
- // include more valuable information. They are included here because they are
63
- // currently not enabled in babel-preset-react. See the below threads for more info:
64
- // https://github.com/babel/babel/issues/4702
65
- // https://github.com/babel/babel/pull/3540#issuecomment-228673661
66
- // https://github.com/facebookincubator/create-react-app/issues/989
67
- plugins . push . apply ( plugins , [
68
- // Adds component stack to warning messages
69
- require . resolve ( 'babel-plugin-transform-react-jsx-source' ) ,
70
- // Adds __self attribute to JSX which React will use for some warnings
71
- require . resolve ( 'babel-plugin-transform-react-jsx-self' ) ,
72
- ] ) ;
73
- }
74
-
75
- if ( env === 'test' ) {
76
- module . exports = {
77
- presets : [
78
- // ES features necessary for user's Node version
79
- [
80
- require ( 'babel-preset-env' ) . default ,
81
- {
82
- targets : {
83
- node : 'current' ,
84
- } ,
85
- } ,
86
- ] ,
87
- // JSX, Flow
88
- require . resolve ( 'babel-preset-react' ) ,
89
- ] ,
90
- plugins : plugins . concat ( [
91
- // Compiles import() to a deferred require()
92
- require . resolve ( 'babel-plugin-dynamic-import-node' ) ,
93
- ] ) ,
94
- } ;
95
- } else {
96
- module . exports = {
97
- presets : [
98
- // Latest stable ECMAScript features
99
- [
100
- require . resolve ( 'babel-preset-env' ) ,
101
- {
102
- targets : {
103
- // React parses on ie 9, so we should too
104
- ie : 9 ,
105
- // We currently minify with uglify
106
- // Remove after https://github.com/mishoo/UglifyJS2/issues/448
107
- uglify : true ,
108
- } ,
109
- // Disable polyfill transforms
110
- useBuiltIns : false ,
111
- // Do not transform modules to CJS
112
- modules : false ,
113
- } ,
114
- ] ,
115
- // JSX, Flow
116
- require . resolve ( 'babel-preset-react' ) ,
117
- ] ,
118
- plugins : plugins . concat ( [
119
- // function* () { yield 42; yield 43; }
120
- [
121
- require . resolve ( 'babel-plugin-transform-regenerator' ) ,
122
- {
123
- // Async functions are converted to generators by babel-preset-env
124
- async : false ,
125
- } ,
126
- ] ,
127
- // Adds syntax support for import()
128
- require . resolve ( 'babel-plugin-syntax-dynamic-import' ) ,
129
- ] ) ,
130
- } ;
131
-
132
- if ( env === 'production' ) {
133
- // Optimization: hoist JSX that never changes out of render()
134
- // Disabled because of issues: https://github.com/facebookincubator/create-react-app/issues/553
135
- // TODO: Enable again when these issues are resolved.
136
- // plugins.push.apply(plugins, [
137
- // require.resolve('babel-plugin-transform-react-constant-elements')
138
- // ]);
139
- }
140
- }
19
+ module . exports = create ( env ) ;
0 commit comments