File tree 1 file changed +15
-1
lines changed
packages/babel-preset-react-app
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 6
6
*/
7
7
'use strict' ;
8
8
9
+ const validateBoolOption = ( name , value , defaultValue ) => {
10
+ if ( typeof value === 'undefined' ) {
11
+ value = defaultValue ;
12
+ }
13
+
14
+ if ( typeof value !== 'boolean' ) {
15
+ throw new Error ( `Preset react-app: '${ name } ' option must be a boolean.` ) ;
16
+ }
17
+
18
+ return value ;
19
+ } ;
20
+
9
21
module . exports = function ( api , opts ) {
10
22
if ( ! opts ) {
11
23
opts = { } ;
@@ -21,6 +33,8 @@ module.exports = function(api, opts) {
21
33
var isEnvDevelopment = env === 'development' ;
22
34
var isEnvProduction = env === 'production' ;
23
35
var isEnvTest = env === 'test' ;
36
+ var isFlowEnabled = validateBoolOption ( 'flow' , opts . flow , true ) ;
37
+
24
38
if ( ! isEnvDevelopment && ! isEnvProduction && ! isEnvTest ) {
25
39
throw new Error (
26
40
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -64,7 +78,7 @@ module.exports = function(api, opts) {
64
78
development : isEnvDevelopment || isEnvTest ,
65
79
} ,
66
80
] ,
67
- [ require ( '@babel/preset-flow' ) . default ] ,
81
+ isFlowEnabled && [ require ( '@babel/preset-flow' ) . default ] ,
68
82
] . filter ( Boolean ) ,
69
83
plugins : [
70
84
// Experimental macros support. Will be documented after it's had some time
You can’t perform that action at this time.
0 commit comments