-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile dependencies with babel-preset-env (#3776)
- Loading branch information
Showing
4 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
module.exports = function(api, opts) { | ||
if (!opts) { | ||
opts = {}; | ||
} | ||
|
||
// This is similar to how `env` works in Babel: | ||
// https://babeljs.io/docs/usage/babelrc/#env-option | ||
// We are not using `env` because it’s ignored in versions > babel-core@6.10.4: | ||
// https://github.com/babel/babel/issues/4539 | ||
// https://github.com/facebookincubator/create-react-app/issues/720 | ||
// It’s also nice that we can enforce `NODE_ENV` being specified. | ||
var env = process.env.BABEL_ENV || process.env.NODE_ENV; | ||
var isEnvDevelopment = env === 'development'; | ||
var isEnvProduction = env === 'production'; | ||
var isEnvTest = env === 'test'; | ||
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) { | ||
throw new Error( | ||
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' + | ||
'`BABEL_ENV` environment variables. Valid values are "development", ' + | ||
'"test", and "production". Instead, received: ' + | ||
JSON.stringify(env) + | ||
'.' | ||
); | ||
} | ||
|
||
return { | ||
presets: [ | ||
isEnvTest && [ | ||
// ES features necessary for user's Node version | ||
require('@babel/preset-env').default, | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
// Do not transform modules to CJS | ||
modules: false, | ||
}, | ||
], | ||
(isEnvProduction || isEnvDevelopment) && [ | ||
// Latest stable ECMAScript features | ||
require('@babel/preset-env').default, | ||
{ | ||
// Do not transform modules to CJS | ||
modules: false, | ||
}, | ||
], | ||
].filter(Boolean), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters