-
-
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
Keeping the path for the static directory in building #714
Comments
Hmm so this problem is about You could give custom middleware a try?, I'm not sure it will work, but it might. |
👍 This is an issue - not for building storybook but just using for dev. Here's how I got it to work with middleware:
I will try to get a PR for this but not sure if I have the time atm |
Thank you for sharing your solution! ❤️ |
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 60 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! |
Hi! @ndelangen @hansthinhle @patrickgordon Im facing the exact same issue. Was this ever solved? Thanks! |
hi @aviramga - my solution that I posted a few up resolved it for us. I never got around doing a PR to resolve it. Might still do that actually now that my memory has been jogged :) |
Hi @patrickgordon. Sadly my issue is only with build-storybook :/ I'm using it with a tool called Percy to find ui issues in my app. Did you manage to find a solution for the build? |
Looks like you can work around this using symlinks: Add a directory with an arbitrary name (e.g.
Then you should be able to achieve what you need with |
@Hypnosphi thanks for the tip! this doesnt seem to work though. All my static files are under a directory named "static" (not public).
Any advice? Thanks |
Which OS are you using? What was the error? |
Mac high sierra @Hypnosphi but just to make sure I understand correctly, to adjust your example to my use case I need to reate a new directory e.g static-link in it put a file named static and in it write ../static Correct? |
OK looks like my instruction for creating symlink was wrong. The correct way is this:
It will create a "file" in static-link directory that can be shared in git (it won't work on Windows though) |
@Hypnosphi I will give it a shot. but does it mean I have to run it every time I ran build-storybook? |
No, it should be persistent |
@Hypnosphi nope, still not working. While building I get a log that says: I followed your instructions above. So I have an empty directory called static-link with a symlink from static to static-link/static What am I doing wrong? Really appreciate you taking the time to help out :) |
And you use |
@Hypnosphi you mean build-storybook -c .storybook -s static-link ? |
Yes |
I do |
Sorry, I mistyped:
|
I'll add my two cents related to this issue. Though I think it's closely related, my solution differs from @mtrabelsi in that I found that simply copying my assets into the ./static directory that is a result of the Because of the subpath, none of the files outside of the /css directory in the /static directory were getting loaded. I am using relative paths for images and fonts (these were the static assets that were failing to load on the deployed version). So requests like const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = async ({ config }) => {
function resolve(dir) {
return path.join(__dirname, '..', dir);
}
// Other configuration properties
config.plugins.push(
new CopyWebpackPlugin({
pattern: [
{
from: path.resolve(__dirname, './_assets'), // My static font and images are located in the .storybook dir
to: './' // Drop both the fonts/ and img/ directory into the root of the build output.
}
]
})
);
return config;
} After this, the images and fonts were loaded appropriately. |
@tmeasday suggests: why can't we make this a |
@vcastro45 I've tested this for both start-storybook & build-storybook, and it seems to work (tested on the Could you create a reproduction repo for me? |
@shilman It's possible, but we'd have to hoist the preset setup up from storybook/lib/core/src/server/manager/manager-config.js Lines 101 to 102 in 9ea455a
to before here: storybook/lib/core/src/server/build-static.js Lines 190 to 191 in 19c2420
And then pass it down to all lower functions in the build / dev chain. It'd also be another moment we'd really want to migrate it all to TS. Since we'd be touching 50% of lib/core's files anyway. |
@ndelangen OOF, let's not do that now then 🙈 |
Yeah we'll do it some day |
@ndelangen I've documented the workaround per discussion with @tmeasday in #11370. Propose that we move this config to |
Do you think a solution like |
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! |
@nfroidure that is an interesting idea for sure! |
@ndelangen I can give a try to it with a PR if you wish. Any chance it gets merged? |
@nfroidure would be doable: storybook/lib/core/src/server/build-dev.js Lines 77 to 93 in 9182d9f
|
Well I have something here : #12222 Some tests are failing but I cannot see any link between those failures and my changes. LMKWYT ;) |
Thank you for this PR @nfroidure ! I'll look at it this week! |
ZOMG!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.6 containing PR #12222 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Is there an example of how to use this new feature? |
Fun fact I stumbled on today, that might be related to the above:
🤷 |
For anyone wondering how to use the feature for mapping the static file directory that was added in #12222. You can map the local path to a remote one using the CLI parameter like so As an example, taking the original question it would work like so: |
None of the images were loading within my pipeline but worked fine locally, ended up being because the components were fetching images using a relative path I ended up doing 2 things:
|
In my root directory, I have a static folder names
public
which is served as/public/...
path from my node server. That means the images and CSS files are served with that/public/
prefix.But when I use StoryBook with the command:
start-storybook -p 6006 -s ./public
The path with
/public/
is no longer available.So I changed the command to
start-storybook -p 6006 -s ./
to serve the root directory, and everything is ok.But when I build my storybook with the command
build-storybook -s ./
the script will copy all files in the root directory to thestorybook-static
.And if I change the command to
build-storybook -s ./public
, the path with/public/
prefix will not be available anymore.Is there a way to specify the path for the static directory?
The text was updated successfully, but these errors were encountered: