Skip to content

Commit ccfe22b

Browse files
Example to show hacky way of getting babel-plugin-styled-components working in create-react-app without macro
1 parent 4bf14fa commit ccfe22b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/babel-preset-react-app/create.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ module.exports = function(api, opts, env) {
5454
);
5555
}
5656

57+
var styledComponentsPluginExists = false;
58+
try {
59+
require.resolve('babel-plugin-styled-components')
60+
styledComponentsPluginExists = true;
61+
} catch (_) {}
62+
5763
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
5864
throw new Error(
5965
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -104,6 +110,12 @@ module.exports = function(api, opts, env) {
104110
isTypeScriptEnabled && [require('@babel/preset-typescript').default],
105111
].filter(Boolean),
106112
plugins: [
113+
styledComponentsPluginExists && [
114+
"babel-plugin-styled-components",
115+
{
116+
"displayName": !isEnvProduction
117+
}
118+
],
107119
// Strip flow types before any other transform, emulating the behavior
108120
// order as-if the browser supported all of the succeeding features
109121
// https://github.com/facebook/create-react-app/pull/5182

0 commit comments

Comments
 (0)