I have set up this repository to demonstrate a new workflow that has been made possible in Drupal 10.1 thanks to the inclusion of the single directory components (SDC).
After you complete the installation process below you'll be able to create new components in Drupal.
We prefer to use ddev for local development. If you don't have it installed, install it using their documentation.
You'll want a working Drupal site, so here's what you would run if you are just checking out this repository
- DDEV:
ddev start
- Composer:
ddev composer i
- Drupal:
ddev drush site:install --account-name=admin --account-pass=admin demo_umami -y
- Install dependencies:
ddev drush en storybook
- Fix permissions:
ddev drush role:perm:add anonymous 'render storybook stories'
- Use the generator to produce stories from any compatible source:
ddev drush storybook:generate-all-stories
- Update yarn:
ddev yarn
- Run storybook and keep it running:
ddev yarn storybook
- Launch Storybook in a browser:
ddev storybook
To prepare your modules and themes for use with storybook you'll mainly rely upon the drush command ddev drush storybook:generate-all-stories
. If you find yourself executing that command frequently you can automate the execute of the command by doing the following:
- SSH into your ddev instance:
ddev ssh
- Run
watch drush storybook:generate-all-stories
The command will run when it detects file changes, or every 2 seconds.
It's quite easy to have issues with storybook and drupal thanks to CORS. If you have trouble loading components via this setup, please first check:
- The permission for the cl_server module is set to allow anonymous users to access the component library.
- The CORS configuration is actually loading:
ddev drush php:eval "var_export(\Drupal::getContainer()->getParameter('cors.config'));"
- Then, you can check if your component is named properly or has some other kind of error.
- Also, check our browser's dev console. It usuallly has a lot of good debugging detail logged there.
Did you get an error that looked like this?
Starting drupal-storybook... Failed to start drupal-storybook: project drupal-storybook project root is already set to /Users/Chris.Weber/OpenSource/drupal-storybook, refusing to change it to /Users/Chris.Weber/OpenSource/test1; you can
ddev stop --unlist drupal-storybook
and start again if the listed project root is in error
That's because you checked out this repo in a folder that isn't named drupal-storybook. No worries. Create a new file in your .ddev folder named config.local.yml. In it add this:
name: --the name of your folder--
Just replace --the name of your folder-- with the name of your folder. Then run ddev start
.