Skip to content

Commit

Permalink
Example to show hacky way of getting babel-plugin-styled-components w…
Browse files Browse the repository at this point in the history
…orking in create-react-app without macro
  • Loading branch information
ForestJohnson authored Jan 24, 2020
1 parent 4bf14fa commit ccfe22b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/babel-preset-react-app/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ccfe22b

Please sign in to comment.