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

Docs: Webpack changes for addons #25656

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/addons/writing-presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ To customize Storybook's Babel configuration and add support for additional feat
<!-- prettier-ignore-end -->

<Callout variant="info">

The Babel configuration is only applied to frameworks that use Babel internally. If you enable it for a framework that uses a different compiler, like [SWC](https://swc.rs/) or [esbuild](https://esbuild.github.io/), it will be ignored.

</Callout>

### Builders
Expand Down Expand Up @@ -199,6 +201,8 @@ However, if you need, you can also customize the template used by Storybook to r

As Storybook relies on [esbuild](https://esbuild.github.io/) instead of Webpack to build the UI, presets that depend on the `managerWebpack` API to configure the manager or load additional files other than CSS or images will no longer work. We recommend removing it from your preset and adjusting your configuration to convert any additional files to JavaScript.

**Learn more about the Storybook addon ecosystem**

- [Types of addons](./addon-types.md) for other types of addons
- [Writing addons](./writing-addons.md) for the basics of addon development
- Presets for preset development
Expand Down
4 changes: 3 additions & 1 deletion docs/api/main-config-babel-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ To adjust your Storybook's Babel setup directly—not via an addon—use [`babel

## `Babel.Config`

See [Babel docs](https://babeljs.io/docs/options).
The options provided by [Babel](https://babeljs.io/) are only applicable if you've enabled the [`@storybook/addon-webpack5-compiler-babel`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-babel) addon.
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

<!-- See [Babel docs](https://babeljs.io/docs/options). -->

## `Options`

Expand Down
8 changes: 7 additions & 1 deletion docs/api/main-config-babel.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ Customize Storybook's [Babel](https://babeljs.io/) setup.

## `Babel.Config`

See [Babel docs](https://babeljs.io/docs/options).
The options provided by [Babel](https://babeljs.io/) are only applicable if you've enabled the [`@storybook/addon-webpack5-compiler-babel`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-babel) addon.

<Callout variant="info">

If you have an existing Babel configuration file (e.g., `.babelrc`), it will be automatically detected and used by Storybook without any additional configuration required.

</Callout>

## `Options`

Expand Down
2 changes: 1 addition & 1 deletion docs/api/main-config-swc.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Customize Storybook's [SWC](https://swc.rs/) setup.

## `SWC.Options`

See SWC's [documentation](https://swc.rs/) for more information.
The options provided by [SWC](https://swc.rs/) are only applicable if you've enabled the [`@storybook/addon-webpack5-compiler-swc`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-swc) addon.

## Options

Expand Down
56 changes: 54 additions & 2 deletions docs/builders/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,57 @@ Additionally, if you're generating a [static build](../api/cli-options.md#build)

<!-- prettier-ignore-end -->

## What about Webpack 4 support?
## Compiler support

Support for Webpack 4 has been removed and is no longer being maintained. If you're upgrading your Storybook, it will automatically use Webpack 5 and attempt to migrate your configuration. However, if you're working with a custom Webpack configuration, you may need to update it to work with Webpack 5. The migration process is necessary to ensure that your project runs smoothly with the latest version of Storybook. You can follow the instructions provided on the Webpack [website](https://webpack.js.org/migrate/5/) to update your configuration.
Out of the box, Storybook provides a compiler-agnostic approach to bundling your project, allowing you to use the same tooling you use to bundle your application (e.g., [Babel](https://babeljs.io/), [SWC](https://swc.rs/)), enabling efficient and performant component development within the ecosystem of Webpack 5-based projects.
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

### SWC

If you're working with a project built using [SWC](https://swc.rs/) for faster builds and improved performance, you can use the [`@storybook/addon-webpack5-compiler-swc`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-swc) addon, allowing you the same performance benefits and compatibility with your project. Run the following command to set up the addon automatically:
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-addon-compiler-swc-auto-install.npm.js.mdx',
'common/storybook-addon-compiler-swc-auto-install.pnpm.js.mdx',
'common/storybook-addon-compiler-swc-auto-install.yarn.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

<Callout variant="info">

Additional options can be provided to customize the SWC configuration. See the [SWC API documentation](../api/main-config-swc.md) for more information.

</Callout>

When enabled, the addon will adjust the Webpack configuration to use the [`swc-loader`](https://swc.rs/docs/usage/swc-loader) as the default loader for JavaScript and TypeScript files and will detect and use your project's SWC configuration.
jonniebigodes marked this conversation as resolved.
Show resolved Hide resolved

### Babel

If you're working with a project that relies on Babel's tooling to provide support for specific features, including TypeScript or other modern JavaScript features, you can use the [`@storybook/addon-webpack5-compiler-babel`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-babel) addon to allow you to include them in your Storybook to ensure compatibility with your project. Run the following command to set up the addon automatically:

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-addon-compiler-babel-auto-install.npm.js.mdx',
'common/storybook-addon-compiler-babel-auto-install.pnpm.js.mdx',
'common/storybook-addon-compiler-babel-auto-install.yarn.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

<Callout variant="info">

Additional options can be provided to customize the Babel configuration. See the [`babel` API documentation](../api/main-config-babel.md) for more information, or if you're working on an addon, the [`babelDefault` documentation](../api/main-config-babel-default.md) for more information.

</Callout>

When enabled, the addon will adjust the Webpack configuration to use the [`babel-loader`](https://webpack.js.org/loaders/babel-loader/) as the default loader for JavaScript and TypeScript files and will detect and use your project's Babel configuration.

## Troubleshooting

Expand Down Expand Up @@ -145,6 +193,10 @@ However, if you're working with a framework that provides a default aliasing con

As Storybook relies on [esbuild](https://esbuild.github.io/) to build its internal manager, support for bundling assets with the `managerWebpack` will no longer have an impact on the Storybook UI. We recommend removing existing `managerWebpack` configuration elements from your Storybook configuration file and bundling assets other than images or CSS into JavaScript beforehand.

### Storybook doesn't run with Webpack 4

Support for Webpack 4 has been removed and is no longer being maintained. If you're upgrading your Storybook, it will automatically use Webpack 5 and attempt to migrate your configuration. However, if you're working with a custom Webpack configuration, you may need to update it to work with Webpack 5. The migration process is necessary to ensure that your project runs smoothly with the latest version of Storybook. You can follow the instructions provided on the Webpack [website](https://webpack.js.org/migrate/5/) to update your configuration.

#### Learn more about builders

- [Vite builder](./vite.md) for bundling with Vite
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```sh
npx storybook@latest add @storybook/addon-webpack5-compiler-babel
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```sh
pnpm dlx storybook@latest add @storybook/addon-webpack5-compiler-babel
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```sh
yarn dlx storybook@latest add @storybook/addon-webpack5-compiler-babel
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```sh
npx storybook@latest add @storybook/addon-webpack5-compiler-swc
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```sh
pnpm dlx storybook@latest add @storybook/addon-webpack5-compiler-swc
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```sh
yarn dlx storybook@latest add @storybook/addon-webpack5-compiler-swc
```
Loading