Storybook for Ember
You may have tried to use our quick start guide to setup your project for Storybook. If you want to set up Storybook manually, this is the guide for you.
This will also help you to understand how Storybook works.
Starter Guide Ember
Storybook has its own Webpack setup and a dev server.
In this guide, we will set up Storybook for your Ember project.
Table of contents
Add @storybook/ember
First of all, you need to add @storybook/ember to your project. To do that, run:
If you don’t have package.json in your project, you’ll need to init it first:
Then add the following NPM script to your package.json in order to start the storybook later in this guide:
In order for your storybook to run properly be sure to be either run
ember serveorember buildbefore running any storybook commands. Runningember servebefore storybook will enable live reloading.
Setup environment
Your environment will be preconfigured using ember-cli-storybook. This will add a preview-head.html, a .env and make sure that your environment is configured to work with live reload.
Create the main file
For a basic Storybook configuration, the only thing you need to do is tell Storybook where to find stories.
To do that, create a file at .storybook/main.js with the following content:
That will load all the stories underneath your ../app directory that match the pattern *.stories.js. We recommend co-locating your stories with your source files, but you can place them wherever you choose.
Write your stories
Now you can write some stories inside the ../stories/index.stories.js file, like this:
It is important that you import the
hbsfunction that is provided by a babel plugin in@storybook/ember
If you are using an older version of Ember <= 3.1 please use this story style
A story is either:
- A single handlebars fragment generated using the
hbsfunction - An object that contains template and context that will be bound to the resulting element
In order to get your storybook to get new changes made to the
foo-baror any other components that are defined in your Ember app you must runember serveas a sidecar for the build files to get generated.
Run your Storybook
Now everything is ready. Run your storybook with:
Now you can change components and write stories whenever you need to.