fix(storybook): restore babelrc for storybook webpack (#14111)

This commit is contained in:
Katerina Skroumpelou 2023-01-03 18:48:54 +02:00 committed by GitHub
parent c1e15a168a
commit 285cf2ecf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -5,7 +5,6 @@ import {
names,
offsetFromRoot,
toJS,
updateJson,
} from '@nrwl/devkit';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

View File

@ -3,6 +3,7 @@ import storiesGenerator from '../stories/stories';
import {
convertNxGenerator,
ensurePackage,
joinPathFragments,
logger,
readProjectConfiguration,
Tree,
@ -53,6 +54,42 @@ export async function storybookConfigurationGenerator(
}
}
/**
* If it's library and there's no .babelrc file,
* we need to generate one if it's not using vite.
*
* The reason is that it will be using webpack for Storybook,
* and webpack needs the babelrc file to be present.
*
* The reason the babelrc file is not there in the first place,
* is because the vitest generator deletes it, since it
* does not need it.
* See:
* packages/react/src/generators/library/lib/create-files.ts#L42
*/
if (
bundler !== 'vite' &&
projectConfig.projectType === 'library' &&
!host.exists(joinPathFragments(projectConfig.root, '.babelrc'))
) {
host.write(
joinPathFragments(projectConfig.root, '.babelrc'),
JSON.stringify({
presets: [
[
'@nrwl/react/babel',
{
runtime: 'automatic',
useBuiltIns: 'usage',
},
],
],
plugins: [],
})
);
}
const installTask = await configurationGenerator(host, {
name: schema.name,
uiFramework: '@storybook/react',