Skip to content

Commit

Permalink
fix(storybook): restore babelrc for storybook webpack (#14111)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Jan 3, 2023
1 parent c1e15a1 commit 285cf2e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/react/src/generators/library/lib/create-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
names,
offsetFromRoot,
toJS,
updateJson,
} from '@nrwl/devkit';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import storiesGenerator from '../stories/stories';
import {
convertNxGenerator,
ensurePackage,
joinPathFragments,
logger,
readProjectConfiguration,
Tree,
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 285cf2e

Please sign in to comment.