-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to deploy storybook into a subpath #1291
Comments
If I'm understanding correctly, you'd like You can just put everything inside Unfortunately, running https requires certificate generation and it's not on our roadmap. If there's still an issue, please reopen this. |
@weslleyaraujo our publicPath is This should allow you to serve |
the link is broken, can you update it, please? |
@ozio It looks like it's probably this one:
The base webpack config might be helpful to link too: |
Hello! In Nextjs, for instance, we have the I've also tried to set Do you guys know a way to config it? |
Facing same issue also. Any ideas? |
same here! |
Same here! Need this feature |
same! |
This an absolute MUST HAVE! 🙌 Please add this possibility to specify a custom path prefix... |
How can we reopen this issue? Its closed but never solved. |
I've just figured this out finally! 🎉 To set the path prefix you need to set // .storybook/main.js
module.exports = {
webpackFinal: async (config, { configType }) => {
config.output.publicPath = '/my-prefix/';
return config;
},
managerWebpack: async (config) => {
config.output.publicPath = '/my-prefix/';
return config;
},
}; Also, I had to build Storybook with the build-storybook -- --preview-url=/my-prefix/iframe.html For some reason, I have found nothing about it in official docs, had to google it a lot... |
It doesn't work for me if I want to deploy Storybook into a subpath. So in my components for an image <img alt="" src="/myImage.png" /> Everything is fine if I deploy Storybook at the root of the site but not into a subpath (/storybook).
Unfortunately nothing allowed me to get the assets to work. |
Thanks a lot, this works perfect for me! |
Still not working for me... what are you guys using to serve your static files / whats your server config like? |
In my case, I serve the storybook in a subpath of a springboot application. |
Here we come again... After upgrade to the latest storybook, the approach with specifying |
I am also facing this problem. I managed to get it working temporarily for the time being by manually adding It will look something like this: <div id="docs-root"></div>
<script>
window['CONFIG_TYPE'] = "PRODUCTION";
window['PREVIEW_URL'] = "/my-prefix/iframe.html"; // HOTFIX
...
</script>
<script src="/my-prefix/runtime~main.XXXXX.manager.bundle.js"></script> Anyone have a better solution? |
I am using build-storybook option <link rel="shortcut icon" type="image/x-icon" href="/my-prefix/favicon.ico">
<script>
window['PREVIEW_URL'] = '/my-prefix/iframe.html';
</script> It's working for me now with |
Thank you everyone who has helped provide instructions for how to get this working. I'll contribute my own small improvement, which I used to serve storybook from
module.exports = {
// See https://github.com/storybookjs/storybook/issues/1291#issuecomment-795251283
webpackFinal: async (config, { configType }) => {
if (configType === 'PRODUCTION') {
config.output.publicPath = '/my-prefix/';
}
return config;
},
managerWebpack: async (config, { configType }) => {
if (configType === 'PRODUCTION') {
config.output.publicPath = '/my-prefix/';
}
return config;
},
};
<!-- See https://github.com/storybookjs/storybook/issues/1291#issuecomment-891379856 -->
<link id="favicon" rel="shortcut icon" type="image/x-icon" href="/my-prefix/favicon.ico" />
<script>
if ('%NODE_ENV%' === 'production') {
window['PREVIEW_URL'] = '/my-prefix/iframe.html';
} else {
document.getElementById('favicon').setAttribute('href', '/favicon.ico');
}
</script> |
if you using Vite + Storybook, then that should be helpful viteFinal: (config, { configType }) => {
// some configs
if (configType === 'PRODUCTION') {
config.base = '/my-prefix/';
}
return config
}, |
Some transformations can be done directly in managerHead, without the need to use See my example here: #7775 (comment) |
I am using Storybook Vite and this config worked for me:
|
Using a fresh install of
|
Summaries of above
After above, you will find that your storybook main frame appears but the stories(iframe.html) doesn't. You should set global var ExamplesBefore deploying your websites to a subpath like const base = '//cdn.example.com/storybook/'; // we usually upload assets to CDN
module.export = {
...
// This is to change configurations of building process of storybook's main frame
managerWebpack: (config, { configType }) => {
if (configType === 'PRODUCTION') {
config.output.publicPath = base;
}
return config;
},
managerHead: (head, { configType }) => {
const injections = [
`<link rel="shortcut icon" type="image/x-icon" href="${base}favicon.ico">`, // This set icon for your site.
`<script>window.PREVIEW_URL = '${base}iframe.html'</script>` , // This decide how storybook's main frame visit stories
]
return configType === 'PRODUCTION'
? `${head}${injections.join('')}`
: head
},
// Or webpackFinal
async viteFinal(config, { configType }) {
if (configType === 'PRODUCTION') {
config.base = base
}
return config;
}
...
} |
The app I'm working at uses Nextjs and we're using the nextjs framework: We've set up storybook to run in a subpath using nginx:
and adding that entry to /etc/hosts
After doing these initial steps, the stories were correctly rendering under I was able to fix that by overriding the const absolutePath = path.resolve(__dirname + '/../')
module.exports = {
//...
webpackFinal: async (config) => {
config.entry = [
`${absolutePath}/node_modules/webpack-hot-middleware/client?reload=true&path=/storybook/__webpack_hmr`,
`${absolutePath}/storybook-config-entry.js`,
]
return config
}, |
I suppose managerWebpack and managerHead are not supported anymore at v7? |
Yeah what are we supposed to do on v7? |
FWIW, I ran into this on v7 and had to do this instead of the webpack configs. // package.json
"build:storybook": "storybook build --disable-telemetry",
"postbuild:storybook": "sed -i 's#<head>#<head>\\n<base href='\/storybook\/'>#' ./storybook-static/index.html" What it essentially does is to add I tried using managerHead: (head, { configType }) => {
if (configType === 'PRODUCTION') {
return (`
<base href="/storybook/">
${head}
`);
}
}, but for some reason, the
My use-case was to deploy to a S3 bucket fronted by a CDN that opens Storybook on |
This issue is from 2017. It's 2023 and I can't figure out how to host Storybook on a path other than root. |
Yeah my previous comment was on April 24, it's now almost October and there's still no clear cut solution for v7. I don't think it's a priority at all (which is crazy because deploying on a subpath is extremely useful) |
I had spent hours on this on v7 until this solution pointed me in the right direction. The "build:storybook": "storybook build",
"postbuild:storybook": "perl -i -p -e 's#<head>#<head>\n\t\t<base href='/storybook/'>#' ./storybook-static/index.html" |
This worked for me, thanks a lot @conor-ob ! |
Yeah what are we supposed to do on v8? |
In V8 you can set base path by extending vite config: #main.ts
const config: StorybookConfig = {
...
async viteFinal(config) {
const { mergeConfig } = await import('vite');
return mergeConfig(config, {
base: '/storybook/',
});
},
}
export default config |
As far as I can tell, the Vite solution doesn't work on Angular storybooks because storybook still only supports the old webpack build system. In the Storybook 8 announcement there was the suggestion that they will support the new build system in Storybook 9
Until then, the perl index.html <base ...> postbuild solution works for me as a hack. |
You should be able to use the |
I'd like to be able to deploy storybook into the subpath of /storybook, such that I can target everything related to storybook in an nginx config to use my local domain of "https://test.dev".
I read that this is possible in the documentation, but couldn't get it working. If i extend the webpack config like so:
It works for the "manager.bundle.js" and "preview.bundle.js", but not for "iframe.html" or webpack hot reloading or local css imported via absolute paths.
Is there an easy way to make sure that all requests related to running storybook get prefixed with /storybook?
Alternatively, is there a way to run storybook w/ https via the cli? I can set the host to 'test.dev, but I need it to be https for it to work in dev.
The text was updated successfully, but these errors were encountered: