title |
---|
Install Storybook |
Use the Storybook CLI to install it in a single command. Run this inside your project’s root directory:
<CodeSnippets paths={[ 'common/init-command.npx.js.mdx', 'common/init-command.yarn.js.mdx', 'common/init-command.pnpm.js.mdx', ]} />
Storybook will look into your project's dependencies during its install process and provide you with the best configuration available.
The command above will make the following changes to your local environment:
- 📦 Install the required dependencies.
- 🛠 Setup the necessary scripts to run and build Storybook.
- 🛠 Add the default Storybook configuration.
- 📝 Add some boilerplate stories to get you started.
- 📡 Set up telemetry to help us improve Storybook. Read more about it here.
<YouTubeCallout id="CtfU1UnizHU" title="New Storybook" style={{ marginTop: '1em' }} />
If all goes well, you should see a setup wizard that will help you get started with Storybook introducing you to the main concepts and features, including how the UI is organized, how to write your first story, and how to test your components' response to various inputs utilizing controls.
If you skipped the wizard, you can always run it again by adding the ?path=/onboarding
query parameter to the URL of your Storybook instance, provided that the example stories are still available.
Storybook comes with a built-in development server featuring everything you need for project development. Depending on your system configuration, running the storybook
command will start the local development server, output the address for you, and automatically open the address in a new browser tab where a welcome screen greets you.
<CodeSnippets paths={[ 'angular/storybook-run-dev.with-builder.js.mdx', 'common/storybook-run-dev.npm.js.mdx', 'common/storybook-run-dev.yarn.js.mdx', 'common/storybook-run-dev.pnpm.js.mdx', ]} />
Storybook collects completely anonymous data to help us improve user experience. Participation is optional, and you may opt-out if you'd not like to share any information.
There are some noteworthy items here:
- A collection of useful links for more in-depth configuration and customization options you have at your disposal.
- A second set of links for you to expand your Storybook knowledge and get involved with the ever-growing Storybook community.
- A few example stories to get you started.
The Storybook CLI includes support for the industry's popular package managers (e.g., Yarn, npm, and pnpm) automatically detecting the one you are using when you initialize Storybook. However, if you want to use a specific package manager as the default, add the --package-manager
flag to the installation command. For example:
<CodeSnippets paths={[ 'common/init-command-custom-package-manager.npx.js.mdx', 'common/init-command-custom-package-manager.yarn.js.mdx', 'common/init-command-custom-package-manager.pnpm.js.mdx', ]} />
If you're working with a custom environment set up or need set up Storybook manually, you can use the --type
flag to specify the framework you need to use. Listed below are the supported frameworks and examples of how to use them:
Framework | Type |
---|---|
Angular | angular |
Ember | ember |
HTML | html |
Next.js | nextjs |
Preact | preact |
Qwik | qwik |
React | react |
Server | server |
Solid | solid |
Svelte | svelte |
Vue 2 | vue |
Vue 3 | vue3 |
Web Components | web-components |
<CodeSnippets paths={[ 'common/init-command-manual-framework.npx.js.mdx', 'common/init-command-manual-framework.yarn.js.mdx', 'common/init-command-manual-framework.pnpm.js.mdx', ]} />
If you previously installed Storybook in a project that uses Webpack 4, it will no longer work. This is because Storybook now uses Webpack 5 by default. To solve this issue, we recommend you upgrade your project to Webpack 5 and then run the following command to migrate your project to the latest version of Storybook:
<CodeSnippets paths={[ 'common/storybook-automigrate.npm.js.mdx', 'common/storybook-automigrate.pnpm.js.mdx', 'common/storybook-automigrate.yarn.js.mdx' ]} />
Out of the box, adding Storybook to an Angular project using the Angular CLI requires you to run the installation command from the root of the project or, if you're working with a monorepo environment, from the directory where the Angular configuration file (i.e., angular.json
) is located as it will be used to set up the builder configuration necessary to run Storybook. However, if you need, you can extend the builder configuration to customize Storybook's behavior. Listed below are the supported options:
Configuration element | Description |
---|---|
"browserTarget" |
Build target to be served using the following format. "example-project:builder:config" |
"tsConfig" |
Location of the TypeScript configuration file, relative to the current workspace. "tsConfig": "./tsconfig.json" . |
"port" |
Port used by Storybook. "port": 6006 |
"host" |
Set up a custom host for Storybook. "host": "http://my-custom-host" |
"configDir" |
Storybook configuration directory location. "configDir": ".storybook" |
"https" |
Starts Storybook with HTTPS enabled. "https": true Requires custom certificate information. |
"sslCa" |
Provides an SSL certificate authority. "sslCa": "your-custom-certificate-authority" Optional usage with "https" |
"sslCert" |
Provides an SSL certificate. "sslCert": "your-custom-certificate" Required for https |
"sslKey" |
Provides an SSL key to serve Storybook. "sslKey": "your-ssl-key" |
"smokeTest" |
Exit Storybook after successful start. "smokeTest": true |
"ci" |
Starts Storybook in CI mode (skips interactive prompts and will not open browser window). "ci": true |
"quiet" |
Filters Storybook verbose build output. "quiet": true |
"docs" |
Starts Storybook in documentation mode. "docs": true |
"styles" |
Provide the location of the application's styles to be used with Storybook. "styles": ["src/styles.css", "src/styles.scss"] |
"stylePreprocessorOptions" |
Provides further customization for style preprocessors resolved to the workspace root. "stylePreprocessorOptions": { "includePaths": ["src/styles"] } |
The Ember framework relies on an auxiliary package named @storybook/ember-cli-storybook
to help you set up Storybook in your project. During the installation process you might run into the following warning message in your terminal:
The ember generate entity-name command requires an entity name to be specified.
For more details, use ember help.
It may be the case that you're using an outdated version of the package and you need to update it to the latest version to solve this issue.
Storybook provides a Svelte addon maintained by the community, enabling you to write stories for your Svelte components using the template syntax. You'll need to take some additional steps to enable this feature.
Run the following command to install the addon.
<CodeSnippets paths={[ 'svelte/svelte-csf-addon-install.yarn.js.mdx', 'svelte/svelte-csf-addon-install.npm.js.mdx', 'svelte/svelte-csf-addon-install.pnpm.js.mdx', ]} />
Update your Storybook configuration file (i.e., .storybook/main.js|ts
) to include it.
<CodeSnippets paths={[ 'svelte/main-config-csf-addon-register.js.mdx', 'svelte/main-config-csf-addon-register.ts.mdx', ]} />
<Callout variant="info" style={{ marginBottom: "2rem" }}>
The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see addon's documentation.
If you're still running into some issues during the installation process, we encourage you to check out the following resources:
- Storybook's Angular README for more information on how to set up Storybook in your Angular project.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's Ember README for more information on how to set up Storybook in your Ember project.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's HTML Webpack README for more information on how to set up Storybook in your HTML project with Webpack 5.
- Storybook's HTML Vite README for more information on how to set up Storybook in your HTML project with Vite.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's Preact Webpack README for more information on how to set up Storybook in your Preact project with Webpack 5.
- Storybook's Preact Vite README for more information on how to set up Storybook in your Preact project with Vite.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's Qwik README for more information on how to set up Storybook in your Qwik project.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's React Webpack README for more information on how to set up Storybook in your React project with Webpack 5.
- Storybook's React Vite README for more information on how to set up Storybook in your React project with Vite.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's SolidJS README for more information on how to set up Storybook in your SolidJS project.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's SvelteKit README for more information on how to set up Storybook in your SvelteKit project.
- Storybook's Svelte Webpack README for more information on how to set up Storybook in your Svelte project with Webpack 5.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's Vue 2 Webpack README for more information on how to set up Storybook in your Vue 2 project with Webpack 5.
- Storybook's Vue 2 Vite README for more information on how to set up Storybook in your Vue 2 project with Vite.
- Storybook's Vue 3 Webpack README for more information on how to set up Storybook in your Vue 3 project with Webpack 5.
- Storybook's Vue 3 Vite README for more information on how to set up Storybook in your Vue 3 project with Vite.
- Storybook's help documentation to contact the community and ask for help.
- Storybook's Web Components Webpack README for more information on how to set up Storybook in your Web Components project with Webpack 5.
- Storybook's Web Components Vite README for more information on how to set up Storybook in your Web Components project with Vite.
- Storybook's help documentation to contact the community and ask for help.
Now that you have successfully installed Storybook and understood how it works, let's continue where you left off in the setup wizard and delve deeper into writing stories.
<IfRenderer renderer={['angular', 'vue', 'web-components', 'ember', 'html', 'svelte', 'preact', 'qwik','solid' ]}>
Now that you installed Storybook successfully, let’s take a look at a story that was written for us.