Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS: Fix out-of-the-box babel handling #19842

Merged
merged 3 commits into from
Nov 19, 2022
Merged

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Nov 15, 2022

What I did

NextJS projects should work out-of-the-box when Storybook is initialized.

  1. Scenario: .babelrc or project babel.config.(m)js(x) file doesn't exist

In this case Next.js >= 12 uses swc to transpile the code. In Storybook
we will still use babel to transpile the code. We use the preset next/babel
and configure it to make the Next.js project work with Storybook. Any SWC/Next compiler
related options are ignored

  1. Scenario: .babelrc or project babel.config.(m)js(x) file exist

Storybook will use the project's babel configuration for transpiling. All options, which
are passed to the next/babel prest are respected.

@valentinpalkovic valentinpalkovic changed the title Add proper Next.js framework support Add proper Next.js > 12 framework support Nov 15, 2022
@valentinpalkovic valentinpalkovic added feature request ci:merged Run the CI jobs that normally run when merged. labels Nov 15, 2022
@valentinpalkovic valentinpalkovic marked this pull request as ready for review November 16, 2022 09:18
@valentinpalkovic valentinpalkovic force-pushed the valentin/swc-babel-nextjs branch 3 times, most recently from b9c0d60 to 8aa2633 Compare November 16, 2022 09:55
@valentinpalkovic valentinpalkovic force-pushed the valentin/swc-babel-nextjs branch from ef4d668 to 44e8a6f Compare November 17, 2022 06:31
NextJS projects should work out-of-the-box when Storybook is initialized.

1. Scenario: .babelrc or project babel.config.(m)js(x) file doesn't exist

In this case Next.js >= 12 uses swc to transpile the code. In Storybook
we will still use babel to transpile the code. We use the preset `next/babel`
and configure it to make the Next.js project work with Storybook. Any SWC/Next compiler
related options are ignored

2. Scenario: .babelrc or project babel.config.(m)js(x) file exist

Storybook will use the project's babel configuration for transpiling. All options, which
are passed to the `next/babel` prest are respected.
@valentinpalkovic valentinpalkovic force-pushed the valentin/swc-babel-nextjs branch from 44e8a6f to 5c09970 Compare November 17, 2022 08:04
@shilman shilman changed the title Add proper Next.js > 12 framework support NextJS: Fix out-of-the-box babel behavior Nov 19, 2022
@shilman shilman changed the title NextJS: Fix out-of-the-box babel behavior NextJS: Fix out-of-the-box babel handling Nov 19, 2022
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. Merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:merged Run the CI jobs that normally run when merged. nextjs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants