Make preset a function to account for different dev settings

Summary: Makes `babel-preset-react-native` a factory function that allows to include/exclude dev tool transforms per transform.

Reviewed By: jeanlauliac

Differential Revision: D5237158

fbshipit-source-id: aa7be0fc0f471575b4ee1c5a0e266e2ed2477fc6
This commit is contained in:
David Aurelio 2017-06-14 09:25:55 -07:00 committed by Facebook Github Bot
parent 5c57601769
commit bc22a4da7e
2 changed files with 15 additions and 9 deletions

View File

@ -10,7 +10,7 @@
var resolvePlugins = require('../lib/resolvePlugins'); var resolvePlugins = require('../lib/resolvePlugins');
var preset = { var base = {
comments: false, comments: false,
compact: true, compact: true,
plugins: resolvePlugins([ plugins: resolvePlugins([
@ -42,11 +42,17 @@ var preset = {
]), ]),
}; };
var env = process.env.BABEL_ENV || process.env.NODE_ENV; var devTools = Object.assign({}, base);
if (!env || env === 'development') { devTools.plugins = devTools.plugins.concat(
preset.plugins = preset.plugins.concat(
resolvePlugins(['transform-react-jsx-source']) resolvePlugins(['transform-react-jsx-source'])
); );
}
module.exports = preset;
module.exports = function(options) {
var withDevTools = options.withDevTools;
if (withDevTools == null) {
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
withDevTools = !env || env === 'development';
}
return withDevTools ? devTools : base;
};

View File

@ -1,6 +1,6 @@
{ {
"name": "babel-preset-react-native", "name": "babel-preset-react-native",
"version": "2.0.0-alpha.1", "version": "2.0.0",
"description": "Babel preset for React Native applications", "description": "Babel preset for React Native applications",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/facebook/react-native/tree/master/babel-preset", "repository": "https://github.com/facebook/react-native/tree/master/babel-preset",