From bc22a4da7ea74d17cd701717268c8e50f001d614 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Wed, 14 Jun 2017 09:25:55 -0700 Subject: [PATCH] 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 --- babel-preset/configs/main.js | 22 ++++++++++++++-------- babel-preset/package.json | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/babel-preset/configs/main.js b/babel-preset/configs/main.js index da3435705..5afbc9061 100644 --- a/babel-preset/configs/main.js +++ b/babel-preset/configs/main.js @@ -10,7 +10,7 @@ var resolvePlugins = require('../lib/resolvePlugins'); -var preset = { +var base = { comments: false, compact: true, plugins: resolvePlugins([ @@ -42,11 +42,17 @@ var preset = { ]), }; -var env = process.env.BABEL_ENV || process.env.NODE_ENV; -if (!env || env === 'development') { - preset.plugins = preset.plugins.concat( - resolvePlugins(['transform-react-jsx-source']) - ); -} +var devTools = Object.assign({}, base); +devTools.plugins = devTools.plugins.concat( + 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; +}; diff --git a/babel-preset/package.json b/babel-preset/package.json index 7ccd20627..f70959ab2 100644 --- a/babel-preset/package.json +++ b/babel-preset/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-react-native", - "version": "2.0.0-alpha.1", + "version": "2.0.0", "description": "Babel preset for React Native applications", "main": "index.js", "repository": "https://github.com/facebook/react-native/tree/master/babel-preset",