From c83fc079737136ae8844a4be2b4bc3b50d50f287 Mon Sep 17 00:00:00 2001 From: benjaminhughes Date: Fri, 11 Nov 2016 11:25:40 -0800 Subject: [PATCH] Making babel to use the babelrc file if we find it Summary: This PR tells babel where the babelrc file is if it has been found in the project root. I know you guys are relying on babel to find it when you tell babel the filename and sourceFilename, this works fine in normal js/node projects, here is an example where this will not work. We have a big repo that can contain a few react-native / js projects. Our build system is similar to BUCK and we keep our third party dependencies in a separate folder (having a global package.json at the project route is not feasible as everyone will have to install every apps dependencies even when they don't need them), the structure looks a bit like this: `third_party/js/.` packages from node_modules `common/js/` common code used by numerous apps, common components, services etc. `my_app/native` the app What's happening is something from `my_app/native` (where the .babelrc file is) is requiring something from `common/js` which is then requiring something from `third_party/js` and so babel has no idea what .babelrc file to use and Closes https://github.com/facebook/react-native/pull/8131 Differential Revision: D4167844 Pulled By: hramos fbshipit-source-id: 3569981e26ff8f8c632d8ae365a1f43a3483b13b --- packager/transformer.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packager/transformer.js b/packager/transformer.js index 0a972982e..eda814674 100644 --- a/packager/transformer.js +++ b/packager/transformer.js @@ -37,11 +37,6 @@ const getBabelRC = (function() { // Let's look for the .babelrc in the first project root. // In the future let's look into adding a command line option to specify // this location. - // - // NOTE: we're not reading the project's .babelrc here. We leave it up to - // Babel to do that automatically and apply the transforms accordingly - // (which works because we pass in `filename` and `sourceFilename` to - // Babel when we transform). let projectBabelRCPath; if (projectRoots && projectRoots.length > 0) { projectBabelRCPath = path.resolve(projectRoots[0], '.babelrc'); @@ -58,6 +53,9 @@ const getBabelRC = (function() { // Require the babel-preset's listed in the default babel config babelRC.presets = babelRC.presets.map((preset) => require('babel-preset-' + preset)); babelRC.plugins = resolvePlugins(babelRC.plugins); + } else { + // if we find a .babelrc file we tell babel to use it + babelRC.extends = projectBabelRCPath; } return babelRC;