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

Core: Document main.js config #9552

Merged
merged 9 commits into from
Jan 27, 2020
2 changes: 2 additions & 0 deletions addons/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Storybook Docs

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook Docs transforms your Storybook stories into world-class component documentation.

**DocsPage.** Out of the box, all your stories get a `DocsPage`. `DocsPage` is a zero-config aggregation of your component stories, text descriptions, docgen comments, props tables, and code examples into clean, readable pages.
Expand Down
2 changes: 2 additions & 0 deletions addons/docs/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Storybook Docs for Angular

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for Angular supports [DocsPage](../docs/docspage.md) for auto-generated docs, and [MDX](../docs/mdx.md) for rich long-form docs.

To learn more about Storybook Docs, read the [general documentation](../README.md). To learn the Angular specifics, read on!
Expand Down
2 changes: 2 additions & 0 deletions addons/docs/ember/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Storybook Docs for Ember

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for Ember supports [DocsPage](../docs/docspage.md) for auto-generated docs, and [MDX](../docs/mdx.md) for rich long-form docs.

To learn more about Storybook Docs, read the [general documentation](../README.md). To learn the Ember specifics, read on!
Expand Down
2 changes: 2 additions & 0 deletions addons/docs/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Storybook Docs for React

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for React supports [DocsPage](../docs/docspage.md) for auto-generated docs, and [MDX](../docs/mdx.md) for rich long-form docs.

To learn more about Storybook Docs, read the [general documentation](../README.md). To learn the React specifics, read on!
Expand Down
2 changes: 2 additions & 0 deletions addons/docs/vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Storybook Docs for Vue

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for Vue supports [DocsPage](../docs/docspage.md) for auto-generated docs, and [MDX](../docs/mdx.md) for rich long-form docs.

To learn more about Storybook Docs, read the [general documentation](../README.md). To learn the Vue specifics, read on!
Expand Down
1 change: 1 addition & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'/guides/guide-svelte/',
],
configurations: [
'/configurations/overview/',
'/configurations/options-parameter/',
'/configurations/default-config/',
'/configurations/custom-webpack-config/',
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/addons/using-addons/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'using-addons'
title: 'Using Addons'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook comes with a variety of "core" addons developed and maintained alongside Storybook. Most examples in this site use [actions](https://github.com/storybookjs/storybook/tree/master/addons/actions) and [links](https://github.com/storybookjs/storybook/tree/master/addons/links). But you can use any third party addons distributed via NPM.

Here's how to do it.
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/addons/writing-addons/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'writing-addons'
title: 'Writing Addons'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

This is a complete guide on how to create addons for Storybook.

## Storybook Basics
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/basics/writing-stories/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'writing-stories'
title: 'Writing Stories'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

A Storybook is a collection of stories. Each story represents a single visual state of a component.

> Technically, a story is a function that returns something that can be rendered to screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'custom-webpack-config'
title: 'Custom Webpack Config'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

You can customize Storybook's webpack setup by providing a `webpack` field in `main.js` file.
The value should be an async function that receives a webpack config and eventually returns a webpack config.

Expand Down
81 changes: 81 additions & 0 deletions docs/src/pages/configurations/overview/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

---
id: 'overview'
title: 'Configuration overview'
---

For CLI options see: [here](/docs/cli-options).

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

## main configuration

Storybook has a few files it uses for configuration, and they are grouped together into a directory (default: `.storybook`).

The most import file is the `main.js` file. This is where general config is declared.

Here's an minimal example of a that file:

```js
module.exports = {
stories: ['../src/components/**/*.stories.js'],
addons: [
'@storybook/addon-essentials',
],
};
```

The addons field can refer to traditional [addons](docs/addons/introduction), but it can also include [presets](/docs/presets/introduction/) extending the config further.

## manager & preview
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

Storybook works by being split into 2 applications, which communicate with each other over a postmessage channel; called the "manager" and "preview".
Copy link

@lidoravitan lidoravitan Jan 25, 2020

Choose a reason for hiding this comment

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

has "how to use postmessage channel to communicate with each other..." already been documented ? if yes, it'd be great to add reference, WDYT?

btw, In general it looks good to me :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Documenting storybook's general architecture is on my todo list, thanks for the review

Choose a reason for hiding this comment

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

Let me know if I can help with that


The preview application is essentially just your stories with a framework agnostic 'router'. Making it so when the manager application tells it so, it renders the correct story.

The manager application renders the UI of [addons](docs/addons/introduction), the navigator and [toolbar](/docs/basics/toolbar-guide/).

There are 2 extra config files, for doing some special runtime configs for each of those 2 applications.

In `preview.js` you can add global [decorators](../../basics/writing-stories/#decorators) and [parameters](../../basics/writing-stories/#parameters):

```js
// preview.js
import { addDecorator } from '@storybook/svelte';
import { withA11y } from '@storybook/addon-a11y';

addDecorator(withA11y);
```

In `manager.js` you can add [UI options](/docs/configurations/options-parameter/#global-options).

```js
// manager.js
import { themes } from '@storybook/theming/create';
import { addons } from '@storybook/addons';

addons.setConfig({
theme: themes.dark,
});
```

## entire main.js config

The `main.js` file is actually a preset! so if you know how to configure storybook, you know how to write a preset, and vice-versa!
So the API of `main.js` is equal to [that of presets](/docs/presets/writing-presets/#presets-api).

Here's an overview of the important configuration properties in `main.js`:

```js
module.exports = {
// and array of glob patterns
stories: ['../src/components/**/*.stories.js'],

// an array of addons & presets
addons: ['@storybook/addon-essentials'],
};
```

## webpack

For how to customize webpack, [view the customize webpack section](/docs/configurations/custom-webpack-config/)
2 changes: 2 additions & 0 deletions docs/src/pages/configurations/typescript-config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'typescript-config'
title: 'TypeScript Config'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

This is a central reference for using Storybook with TypeScript.

## Typescript configuration presets
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/presets/introduction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'introduction'
title: 'Intro to Presets'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

Storybook **presets** are grouped collections of `babel`, `webpack`, and `addons` configurations that support specific use cases.

For example, to write your stories in Typescript, rather than [manually configuring Storybook for typescript](../../configurations/typescript-config/) with individual [babel](../../configurations/custom-babel-config/) and [webpack](../../configurations/custom-webpack-config/) configs, you can use the `@storybook/preset-typescript` package, which does the heavy lifting for you.
Expand Down
31 changes: 28 additions & 3 deletions docs/src/pages/presets/writing-presets/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: 'writing-presets'
title: 'Writing Presets'
---

> migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring storybook.

[Storybook presets](../introduction/) are grouped collections of `babel`, `webpack`, and `addons` configurations that support specific use cases in Storybook, such as typescript or MDX support.
Copy link
Member

Choose a reason for hiding this comment

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

"Addons" needs to be updated

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean by this?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do I need to change it to?

Copy link
Member

Choose a reason for hiding this comment

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

This page documents entries and managerEntries, but does not document addons or provide examples (addons is empty []) up and down the page. we should document it for completeness, esp. since this changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, thanks for he explanation, I'll add it

Copy link
Member Author

Choose a reason for hiding this comment

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

How does this look?


This doc covers the [presets API](#presets-api) and how to use the presets mechanism for [advanced configuration](#advanced-configuration).
Expand Down Expand Up @@ -99,6 +101,31 @@ module.exports = {
};
```

### Addons

For users, the name `managerEntries` might be a bit too technical, so instead both users and preset-authors can simply use the property: `addons`:

```js
module.exports = {
addons: ['@storybook/addon-storysource/register'],
};
```

The array of values can support both references to other presets and addons that should be included into the manager.

This was decided so users didn't have to learn more concepts and the minor differences. Storybook will detect whether the module references a preset or an managerEntry and will do the appropriate thing.
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

Here's what it looks when combining presets and managerEntries in the addons property:

```js
module.exports = {
addons: [
'@storybook/addon-storysource/register', // a managerEntry
'@storybook/addon-docs/preset', // a preset
],
};
```

### Entries

Entries are the place to register entry points for the preview. For example it could be used to make a basic configure-storybook preset that loads all the `*.stories.js` files into SB, instead of forcing people to copy-paste the same thing everywhere.
Expand Down Expand Up @@ -128,7 +155,6 @@ module.exports = {
babel: async (config, options) => {
return config;
},
addons: [],
};
```

Expand All @@ -140,7 +166,7 @@ Change your `main.js` file to:
const path = require('path');

module.exports = {
presets: [path.resolve('./.storybook/my-preset')],
addons: [path.resolve('./.storybook/my-preset')],
};
```

Expand All @@ -162,7 +188,6 @@ module.exports = {
babel: async (config, options) => {
return config;
},
addons: [],
};
```

Expand Down