From ccfe22bd251f0e8346bbf7c9ad82c1eaae454d38 Mon Sep 17 00:00:00 2001 From: Forest Johnson Date: Fri, 24 Jan 2020 13:36:22 -0600 Subject: [PATCH] Example to show hacky way of getting babel-plugin-styled-components working in create-react-app without macro --- packages/babel-preset-react-app/create.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/babel-preset-react-app/create.js b/packages/babel-preset-react-app/create.js index 24b007f69a2..75f7667bd61 100644 --- a/packages/babel-preset-react-app/create.js +++ b/packages/babel-preset-react-app/create.js @@ -54,6 +54,12 @@ module.exports = function(api, opts, env) { ); } + var styledComponentsPluginExists = false; + try { + require.resolve('babel-plugin-styled-components') + styledComponentsPluginExists = true; + } catch (_) {} + if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) { throw new Error( 'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' + @@ -104,6 +110,12 @@ module.exports = function(api, opts, env) { isTypeScriptEnabled && [require('@babel/preset-typescript').default], ].filter(Boolean), plugins: [ + styledComponentsPluginExists && [ + "babel-plugin-styled-components", + { + "displayName": !isEnvProduction + } + ], // Strip flow types before any other transform, emulating the behavior // order as-if the browser supported all of the succeeding features // https://github.com/facebook/create-react-app/pull/5182