- Notifications
You must be signed in to change notification settings - Fork71
Deploy your storybook as a static site
License
storybook-eol/storybook-deployer
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a simple tool allows you to deploy your Storybook into a static hosting service. (Currently, GitHub Pages and AWS S3 beta)
$ storybook-to-ghpages --help$ storybook-to-aws-s3 --helpOptions: --help, -h Show help. [boolean] --version Show version number [boolean] --existing-output-dir, -e If you have previously built your storybook output (through a different CI step, etc) and just need to publish it [string] --out, -o Configure the output directory [string] --packages, -p Directoryfor package.jsons (monorepo support) [string] --monorepo-index-generator, -m Path to file to customize the monorepo index.html. This function shouldreturn the htmlfor the page. [string] --script, -s Specify the build scriptin your package.json [string] --ci Deploy the storybookin CI mode (github only) [boolean] --dry-run Run build but hold off on publishing [boolean] --remote Git remote to push to [string] [default:"origin"] --branch Git branch to push to [string] [default:"gh-pages"] --source-branch Source branch to push from [string] [default:"master"] --host-token-env-variable, -t Github tokenfor CI publish [string] [default:"GH_TOKEN"] --aws-profile AWS profile to usefor publishing. Use NONE to use no profile at all instead of"default". [string] [default:"default"] --bucket-path AWS bucket path to usefor publishing [string] --s3-sync-options Additional options to pass to AWSCLI s3 sync [string]
Install Storybook Deployer with:
npm i @storybook/storybook-deployer --save-devThen add a NPM script like this for github page:
{"scripts": {"deploy-storybook":"storybook-to-ghpages" }}or like this for AWS S3:
{"scripts": {"deploy-storybook":"storybook-to-aws-s3" }}Then you can runnpm run deploy-storybook to deploy the Storybook.
Alternatively, you can execute Storybook Deployer directly usingnpx
npx -p @storybook/storybook-deployer storybook-to-ghpagesnpx -p @storybook/storybook-deployer storybook-to-aws-s3
If you customize the build configuration with some additional params (like static file directory), then you need to expose another NPM script like this:
{"scripts": {"build-storybook":"build-storybook -s public" }}If you need to configure the output directory you can supply theout flag.
npm run deploy-storybook -- --out=.out
If you have previously built your storybook output (through a different CI step, etc) and just need to publish it, specify the directory like this:
npm run deploy-storybook -- --existing-output-dir=.out
if you want to see how everything build without pushing to a remote, use the--dry-run flag.
npm run deploy-storybook -- --dry-run
If you manage a monorepo with multiple storybooks you can pass thepackages flag todeploy-storybook to scan a directory forpackage.jsons.
The following command will search thepackages directory for packages. It will also generate a defaultindex.html that links to all of the loaded storybooks.
npm run deploy-storybook -- --packages packages
To customize the monorepoindex.html you can pass themonorepo-index-generator flag todeploy-storybook. This file should export a function that receive the following arguments and returns the html for the page.
- an array of all the
package.jsondata from the loaded storybooks as the first argument - the output directory
npm run deploy-storybook -- --monorepo-index-generator my-custom-generator.js
To deploy Storybook as part of a CI step, pass theci flag tonpm run deploy-storybook.
If theCI environment variable is set then this mode will be assumed, therefore no need to specify theci flag.
Because pushing to GitHub as part of a CI step requires apersonal access token, Storybook uses theGH_TOKEN environment variable, by default, to authenticate GitHub pushes.
This environment variable name can be configured via thehost-token-env-variable flag.
For example, if your access token is stored in theGH_TOKEN environment variable
npm run deploy-storybook -- --ci
Or if your access token is stored in theGITHUB_TOKEN environment variable
npm run deploy-storybook -- --ci --host-token-env-variable=GITHUB_TOKEN
If you are deploying Storybook to GitHub Pages from a repository belonging to an organization account on GitHub, you may need to specify a${{ github.actor }} in addition to the${{ secrets.GITHUB_TOKEN }} for your build step to be able to authenticate properly.
For instance:
- name: Deploy storybook to GitHub Pages run: npm run deploy-storybook -- --ci env: GH_TOKEN: ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}If you want to customize Git username, email or commit message, add this topackage.json:
"storybook-deployer": {"gitUsername":"Custom Username","gitEmail":"custom@email.com","commitMessage":"Deploy Storybook [skip ci]"}
It will override the default configuration:
"storybook-deployer": {"gitUsername":"GH Pages Bot","gitEmail":"hello@ghbot.com","commitMessage":"Deploy Storybook to GitHub Pages"}
To deploy Storybook to a remote other thanorigin, pass a--remote flag tonpm run deploy-storybook.For example, to deploy to yourupstream remote:
npm run deploy-storybook -- --remote=upstream
Or, to specify a target branch and serve your storybook with rawgit instead of gh-pages:
npm run deploy-storybook -- --branch=feature-branch
Or, to specify a source branch other thanmaster, pass a--source-branch flag tonpm run deploy-storybook:
npm run deploy-storybook -- --source-branch=release
For AWS S3 deployment you must haveawscli installed.
You must specify a bucket path withbucket-path option:my-bucket-name/path/to/destination-folder-in-bucket and have the rights to write to this bucket.
You can change the aws profile used to run the command with theaws-profile option.
storybook-to-aws-s3 --bucket-path=my-bucket-name/path/to/destination-folder-in-bucket --aws-profile=myprofile
You can exclude the aws profile by setting this flag to "NONE":
storybook-to-aws-s3 --bucket-path=my-bucket-name/path/to/destination-folder-in-bucket --aws-profile=NONE
You can provide arbitrary S3 sync options via the--s3-sync-options flag:
storybook-to-aws-s3 --bucket-path=bucket-name/bucket-path --s3-sync-options=--acl=public-readstorybook-to-aws-s3 --bucket-path=bucket-name/bucket-path --s3-sync-options="--acl=public-read --quiet"Thanks goes to these wonderful people (emoji key):
This project follows theall-contributors specification. Contributions of any kind welcome!
About
Deploy your storybook as a static site
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.