Skip to content

Commit

Permalink
Added smartness to preview.js to detect github builds and prepare for…
Browse files Browse the repository at this point in the history
… pages deploy properly.
  • Loading branch information
patcon committed Oct 8, 2024
1 parent 5ab870e commit b3a38e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ const config = {
name: "@storybook/react-webpack5",
options: {},
},
env: (config) => ({
...config,
GITHUB_REPOSITORY: process.env["GITHUB_REPOSITORY"] || null,
}),
};
export default config;
8 changes: 8 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type { import('@storybook/react').Preview } */
const isGithubBuild = !!process.env["GITHUB_REPOSITORY"]
const preview = {
parameters: {
branches: {
Expand All @@ -13,4 +14,11 @@ const preview = {
},
};

if (isGithubBuild) {
const [owner, repo] = process.env["GITHUB_REPOSITORY"].split("/")
preview.parameters["branches"] = {
hostname: `${owner}.github.io/${repo}`,
}
}

export default preview;

0 comments on commit b3a38e2

Please sign in to comment.