Skip to content

Commit

Permalink
feat(storybook): Custom .babelrc in Storybook (#10551)
Browse files Browse the repository at this point in the history
  • Loading branch information
veimox committed Jun 7, 2022
1 parent 8ed3c70 commit 52f824c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
4 changes: 4 additions & 0 deletions docs/generated/packages/storybook.json
Expand Up @@ -307,6 +307,10 @@
"type": "string",
"description": "Path to storybook preview.js file."
},
"babelrcPath": {
"type": "string",
"description": "Path to storybook .babelrc file."
},
"srcRoot": {
"type": "string",
"description": "Project source path."
Expand Down
53 changes: 29 additions & 24 deletions packages/react/plugins/storybook/index.ts
Expand Up @@ -147,31 +147,36 @@ export const webpack = async (
'11.0.0'
)
) {
const babelrc = readJsonFile(
joinPathFragments(options.configDir, '../', '.babelrc')
);
if (babelrc?.plugins?.includes('@emotion/babel-plugin')) {
resolvedEmotionAliases = {
resolve: {
alias: {
'@emotion/core': joinPathFragments(
workspaceRoot,
'node_modules',
'@emotion/react'
),
'@emotion/styled': joinPathFragments(
workspaceRoot,
'node_modules',
'@emotion/styled'
),
'emotion-theming': joinPathFragments(
workspaceRoot,
'node_modules',
'@emotion/react'
),
try {
const babelrc = readJsonFile(
options.babelrcPath ||
joinPathFragments(options.configDir, '../', '.babelrc')
);
if (babelrc?.plugins?.includes('@emotion/babel-plugin')) {
resolvedEmotionAliases = {
resolve: {
alias: {
'@emotion/core': joinPathFragments(
workspaceRoot,
'node_modules',
'@emotion/react'
),
'@emotion/styled': joinPathFragments(
workspaceRoot,
'node_modules',
'@emotion/styled'
),
'emotion-theming': joinPathFragments(
workspaceRoot,
'node_modules',
'@emotion/react'
),
},
},
},
};
};
}
} catch (error) {
// silently ignore if the .babelrc doesn't exist
}
}
return mergeWebpack.merge(
Expand Down
4 changes: 4 additions & 0 deletions packages/storybook/src/executors/storybook/schema.json
Expand Up @@ -76,6 +76,10 @@
"type": "string",
"description": "Path to storybook preview.js file."
},
"babelrcPath": {
"type": "string",
"description": "Path to storybook .babelrc file."
},
"srcRoot": {
"type": "string",
"description": "Project source path."
Expand Down

0 comments on commit 52f824c

Please sign in to comment.