Skip to content

Storybook Deployment Guide โ€‹

Complete guide for deploying the Storybook component library to storybook.ourlantern.app and storybook.dev.ourlantern.app.

Overview โ€‹

The Storybook site is separate from the main Lantern app and documentation, with its own deployment pipeline:

ComponentProductionDevelopment
Main Appourlantern.appdev.ourlantern.app
Docs Sitedocs.ourlantern.appdocs.dev.ourlantern.app
Storybookstorybook.ourlantern.appstorybook.dev.ourlantern.app

Key Benefits:

  • Stakeholders can view and interact with components without local setup
  • Designers can review component variations and documentation
  • Developers can share component examples via URLs
  • Independent deployment from main app
  • Automatic preview URLs for component changes

Deployment Flow โ€‹

Push to GitHub (main or dev branch)
    โ†“
Cloudflare Pages Git Integration
    โ†“
Build static Storybook (npm run build-storybook)
    โ†“
Deploy to Cloudflare Pages
    โ†“
Available at storybook.ourlantern.app (main) or storybook.dev.ourlantern.app (dev)

Automatic Deployments โ€‹

  • main branch โ†’ storybook.ourlantern.app (production)
  • dev branch โ†’ storybook.dev.ourlantern.app (development)
  • feature branches โ†’ Preview URLs (e.g., feature-xyz.lantern-storybook-dev.pages.dev)

Quick Start โ€‹

Local Development โ€‹

bash
# Start the Storybook dev server
npm run storybook

# Build Storybook for production (static site)
npm run build-storybook

# Preview the production build
npx http-server storybook-static

The dev server runs on http://localhost:6006 by default.

Initial Setup in Cloudflare โ€‹

Step 1: Create Production Storybook Project โ€‹

  1. Go to Cloudflare Dashboard โ†’ Pages
  2. Click "Create a project" โ†’ "Connect to Git"
  3. Select cattreedev/lantern_app repository
  4. Configure:
    • Project name: lantern-storybook
    • Production branch: main
    • Build command: npm run build-storybook
    • Build output directory: storybook-static
    • Root directory: (leave empty)
  5. Click "Save and Deploy"

Step 2: Create Development Storybook Project โ€‹

  1. Click "Create a project" again
  2. Select same repo cattreedev/lantern_app
  3. Configure:
    • Project name: lantern-storybook-dev
    • Production branch: dev (not main!)
    • Build command: npm run build-storybook
    • Build output directory: storybook-static
    • Root directory: (leave empty)
  4. Click "Save and Deploy"

Step 3: Add Custom Domains โ€‹

Production Storybook โ€‹

  1. In lantern-storybook project, go to Custom domains
  2. Click Set up a custom domain
  3. Enter storybook.ourlantern.app
  4. Cloudflare will auto-create the required DNS records

Development Storybook โ€‹

  1. In lantern-storybook-dev project, go to Custom domains
  2. Click Set up a custom domain
  3. Enter storybook.dev.ourlantern.app
  4. Cloudflare will auto-create the required DNS records

Step 4: Verify DNS Configuration โ€‹

In Cloudflare dashboard, DNS tab should show:

CNAME  storybook      โ†’ lantern-storybook.pages.dev        (Proxied)
CNAME  storybook.dev  โ†’ lantern-storybook-dev.pages.dev    (Proxied)

Note: These are in addition to your existing DNS records:

CNAME  @              โ†’ lantern-app.pages.dev              (Proxied)
CNAME  dev            โ†’ lantern-app-dev.pages.dev          (Proxied)
CNAME  docs           โ†’ lantern-docs.pages.dev             (Proxied)
CNAME  docs.dev       โ†’ lantern-docs-dev.pages.dev         (Proxied)

Deployment Workflow โ€‹

Updating Storybook โ€‹

1. Make Changes โ€‹

bash
# Create a feature branch
git checkout -b feature/update-button-story dev

# Add or update stories
# Stories are in src/**/*.stories.jsx

# Test locally
npm run storybook

2. Preview Changes โ€‹

bash
# Build static Storybook
npm run build-storybook

# Verify the build
ls -la storybook-static/

# Optional: preview locally
npx http-server storybook-static

3. Push to GitHub โ€‹

bash
git add .
git commit -m "Add button variants to Storybook"
git push origin feature/update-button-story

Result: Cloudflare creates a preview URL automatically:

  • https://feature-update-button-story.lantern-storybook-dev.pages.dev
  • Share this URL with stakeholders for review!

4. Merge to Dev โ€‹

After review:

bash
git checkout dev
git merge feature/update-button-story
git push origin dev

Result: Deploys to https://storybook.dev.ourlantern.app

5. Deploy to Production โ€‹

When ready for production:

bash
git checkout main
git merge dev
git push origin main

Result: Deploys to https://storybook.ourlantern.app


Managing Access (Optional) โ€‹

By default, Storybook sites are public. This is ideal for:

  • Sharing with designers and product managers
  • External stakeholder reviews
  • Component library documentation

Restricted Access (If Needed) โ€‹

If you need to restrict access:

  1. Go to Cloudflare Zero Trust โ†’ Access โ†’ Applications
  2. Click Add an application โ†’ Self-hosted
  3. Configure:
    • Application name: lantern-storybook
    • Domain: storybook.ourlantern.app
    • Policy: Choose authentication method (PIN, email, etc.)
  4. Repeat for dev environment if needed

Note: For stakeholder access, keeping it public is usually better.


Using Storybook for Reviews โ€‹

Sharing Components with Stakeholders โ€‹

  1. Direct links to components:

    https://storybook.ourlantern.app/?path=/story/components-button--default
  2. Canvas mode (component only):

    https://storybook.ourlantern.app/iframe.html?id=components-button--default
  3. Docs mode (with documentation):

    https://storybook.ourlantern.app/?path=/docs/components-button--docs

Preview URLs for Feature Branches โ€‹

Every feature branch gets a preview URL:

https://[branch-name].lantern-storybook-dev.pages.dev

Share these URLs in:

  • Pull request descriptions
  • Slack/email for design reviews
  • Jira/Linear tickets
  • Design handoff documents

Troubleshooting โ€‹

Build Fails in Cloudflare โ€‹

Check the build logs:

  1. Go to Cloudflare Dashboard โ†’ Pages โ†’ your project
  2. Click on the failed deployment
  3. View the build log

Common issues:

  • Missing dependencies: Check package.json has all Storybook packages
  • Build command wrong: Should be npm run build-storybook
  • Output directory wrong: Should be storybook-static

Storybook Shows Blank Page โ€‹

Possible causes:

  • Base path misconfiguration
  • Missing static assets
  • Build didn't complete successfully

Fix:

  1. Build locally: npm run build-storybook
  2. Check storybook-static/ has files
  3. Look for JavaScript errors in browser console

Stories Not Updating โ€‹

Ensure you're looking at the right environment:

  • Production (main branch): storybook.ourlantern.app
  • Development (dev branch): storybook.dev.ourlantern.app
  • Feature branch: [branch-name].lantern-storybook-dev.pages.dev

Force a rebuild:

  1. Go to Cloudflare Pages โ†’ Deployments
  2. Click "Retry deployment" on the latest build

Custom Domain Not Working โ€‹

Check DNS records:

bash
nslookup storybook.ourlantern.app
# Should resolve to lantern-storybook.pages.dev

If not resolving:

  1. Go to Cloudflare Dashboard โ†’ DNS
  2. Verify CNAME record exists and is proxied (orange cloud)
  3. Wait 5-10 minutes for DNS propagation

Build Configuration โ€‹

Wrangler Config โ€‹

The wrangler.storybook.toml file defines the build configuration:

toml
name = "lantern-storybook"
compatibility_date = "2026-01-03"

[pages]
  build_command = "npm run build-storybook"
  build_output_directory = "storybook-static"
  node_version = "20"

Package.json Scripts โ€‹

json
{
  "scripts": {
    "storybook": "storybook dev -p 6006",
    "build-storybook": "storybook build"
  }
}

Best Practices โ€‹

Development Workflow โ€‹

  1. Always test locally first: npm run storybook
  2. Build before pushing: npm run build-storybook to catch build errors
  3. Use feature branches: Get preview URLs for reviews
  4. Merge to dev first: Test on dev environment before production
  5. Keep stories updated: Add stories for new components immediately

Stakeholder Communication โ€‹

  1. Share preview URLs early: Get feedback during development
  2. Use descriptive branch names: Makes preview URLs clearer
  3. Add documentation to stories: Use MDX or description fields
  4. Group related components: Use consistent naming in story titles

Performance โ€‹

  1. Optimize images: Use compressed images in stories
  2. Lazy load large components: Use code splitting if needed
  3. Monitor build times: Keep builds under 5 minutes

  • DEPLOYMENT.md โ€” Main app deployment guide
  • DOCS_DEPLOYMENT.md โ€” Documentation site deployment
  • SUBDOMAINS_AND_ACCESS.md โ€” DNS and access management
  • docs/storybook/STORYBOOK.md โ€” Storybook usage guide
  • docs/storybook/ADDING_STORIES.md โ€” How to add new stories

Quick Reference โ€‹

URLs โ€‹

EnvironmentURL
Production Storybookhttps://storybook.ourlantern.app
Dev Storybookhttps://storybook.dev.ourlantern.app
Preview (feature branch)https://[branch-name].lantern-storybook-dev.pages.dev

Commands โ€‹

bash
# Local development
npm run storybook

# Build static site
npm run build-storybook

# Preview build
npx http-server storybook-static

# Push and deploy
git push origin [branch-name]

Cloudflare Projects โ€‹

  • Production: lantern-storybook (main branch โ†’ storybook.ourlantern.app)
  • Development: lantern-storybook-dev (dev branch โ†’ storybook.dev.ourlantern.app)

Built with VitePress