feat(storybook): Custom .babelrc in Storybook (#10551)

This commit is contained in:
Jorge Rodriguez 2022-06-07 23:18:34 +02:00 committed by GitHub
parent 8ed3c7071a
commit 52f824cfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 24 deletions

View File

@ -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."

View File

@ -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(

View File

@ -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."