-
-
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
Setting publicPath almost works. #3172
Comments
There's some related discussion in #3010 (comment) |
In case of static build, you can just serve |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
@bionikspoon Did you ever resolve your issue besides using a redirect? I'm also running into the same issue setting up the static content to load in a django application. |
@xiaolin no, still using the redirect. |
What happens if you don't override publicPath from our default config? |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
I really can't change webpack's If this is really impossible at the moment, I wonder if there's a workaround? -- edited |
What do you need that for, @chardskarth ? |
Well. Intuitively, I thought to be able to control webpack’s custom output path, I’d simply have to edit ‘output.path’. But then **there’s no other way to control the output directory but to use the ‘—output-dir’ option. And what do I need this for? To control storybook-build’s path. |
So what's wrong with this? |
It may be just me. But I find this not intuitive. |
@xiaolin I have just made the redirect solution in django. with the following view and url
@chardskarth were you able to make this work without the redirect? can you provide an example? |
Just like what you mentioned to @xiaolin, I made the solution directly in java spring.
|
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
If you visit |
OK, you need a redirect then |
I'm running into a similar issue as @kimamula, but in my case I'm trying to include the middleware for the server in an existing Express app, mounted at If I make the request to |
I feel like setting up server-side redirects is not the best solution for a client-side application. What if Storybook simply obeyed the consumer's setting for |
static dir path mapping to a custom endpoint was added in this PR but it is available only in alpha version (6.1.0-alpha.23) |
I've just figured this out finally! To fully 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... |
Hey, thank you that's giving me hope about custom publicPath In my case with Storybook version 6.2.9 I just need managerWebpack configuration and giving some extra config because --preview-url doesn't seem to works // .storybook/main.js
module.exports = {
managerWebpack: async (config) => {
configHtmlWebPackPlugin = config.plugins.find(plugin => plugin.constructor.name === 'HtmlWebpackPlugin')
configHtmlWebPackPlugin.options.publicPath = '/assets/storybook/'
config.output.publicPath = '/assets/storybook/'
const oriTemplateParameters = configHtmlWebPackPlugin.options.templateParameters
configHtmlWebPackPlugin.options.templateParameters = (compilation, files, options) => {
oriReturn = oriTemplateParameters(compilation, files, options)
oriReturn.globals.PREVIEW_URL = '/assets/storybook/iframe.html'
return oriReturn
}
return config;
}
}; you can replace /assets/storybook with your any prefix Thanks |
Sorry, i cant understand this implementation, could you show the full implementation file? Thanks |
Hey Bruno, .storybook/main.js function injectCustomPublicPath(configWebpack, publicPath) {
configWebpack.output.publicPath = publicPath
configHtmlWebPackPlugin = configWebpack.plugins.find(
(plugin) => plugin.constructor.name === 'HtmlWebpackPlugin',
)
configHtmlWebPackPlugin.options.publicPath = publicPath
const oriTemplateParameters =
configHtmlWebPackPlugin.options.templateParameters
configHtmlWebPackPlugin.options.templateParameters = (
compilation,
files,
options,
) => {
oriReturn = oriTemplateParameters(compilation, files, options)
oriReturn.globals.PREVIEW_URL = `${publicPath}iframe.html`
return oriReturn
}
}
module.exports = {
managerWebpack: async (config) => {
// change access url storybook to URL sub path ex: domain.com/assets/storybook
injectCustomPublicPath(config, '/assets/storybook/')
return config
},
}
|
Issue details
Overriding
config.output.publicpath
does not work.Here's the scenario:
As a developer, I want QA and Design teams to be able to review storybook on review apps. I want to be able to publish storybook as a path on my main app: for example
pr-2200.example.com/storybook/
.If I set public path, it almost works:
There's one line, that seems to ignore webpack's publicPath:
https://github.com/storybooks/storybook/blob/abd4f0ef697c0b62ee724fd88e3c245efd4bd912/lib/core/src/client/manager/provider.js#L34
As a hack, I can fix this, by creating a redirect on my server.
For example, on rails, I can do:
(edited this snippet):
redirect('/storybook/iframe.html')
->redirect(path: '/storybook/iframe.html')
. This subtle change forwards url params with the redirect.And everything works!
It would better if everything worked without creating a redirect on my server.
Please specify which version of Storybook and optionally any affected addons that you're running
Affected platforms
The text was updated successfully, but these errors were encountered: